I have an HTML simple web form to find a specific store in Google Maps by just entering the zip code or the city name. The search form must be targeted to the map like this:
https://www.google.com/maps/search/storename+cityname
Because people know they are going to get results of only Storename, they only write in the input text the zip code or city name so the store name is hidden but parsed after clicking to submit.
I am trying to achieve it like this:
<form action="https://www.google.com/maps/search/storename+city" method="get">
<input type="text" name="city"><input type="submit">
</form>
Any idea how to achieve this ?
Lets say the store name is: Apple
People will only enter the city name for example Miami (in the text field) and the form will in some way redirect the user to https://www.google.com/maps/search/apple+miami
2
Answers
Based on your comment, this would be enough. I’m using jQuery, since it’s in the tags of your question.
Vanilla JS solution
Some advice – I would add some sort of a unique identifier to the form (id, for example). This is so you would specifically target the form you want, instead of the first one to be found on your site (which is what
document.querySelector
does).An alternative approach than the above would be to intercept the form submission and modify the form action before continuing the form submission process.