Search code examples
javascriptgoogle-mapsprompt

Proper Way to receive number Input From User - Javascript


I created the webpage where is the google map, and every user can input some data. The user just clicks on the map and the marker on map appears.

Now I would like to get the number from the user and place it just under the marker.

It's working, but I'm getting data by:

prompt();

But I find this way as horrible and bad looking for the user. The user can also disable the prompts in a browser. Also on the mobile prompt() looks awful. Any suggestions?


Solution

  • You could use a regular HTML <form> on the page and then override the form submit to pass data into your javascript instead of refreshing the page.

    If you're using jQuery, here is a helpful API to get you started. https://api.jquery.com/category/forms/

    Here are some other options: Alternative to Javascript prompt box