javascript - Getting user location with form submit -


hello im using html5 geolocation , after user submits form want store longtitude , latitude problem has appeared

i made onclick="" event on submit button , when button pressed js coordinations , put them hidden fields in form , form sent php , whenever submit form , small popup come out , asks permission location , imediately dissapears thats because of php refreshed page , should ? said when click submit form button js triggered , ask permission after permission accepted hidden fields filled coordination data , form sent server , after press button popup allowing location go out 1 second , imediately dissapear , page refresh no result , how can fix ?

one simple way solve run js code detects location , asks permission when form first loads in page, not when it's submitted.

your issue you're trying execute javascript simultaneously form submits. unless override default behaviour, form submit anyway regardless of scripts run in onclick event, , not wait them.

the other way override default submit behaviour. assuming have jquery loaded, handle click this:

$(function() {   $("#mysubmitbutton").click(function(event) {     event.preventdefault(); //stops form submitting     //here write code asks location , puts in hidden fields    $("#myform").submit(); //only submit form, manually.   }); }); 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -