javascript - After script Geocoder form is empty -
i have 2 fields results, 1 field input: address. after clicking on button, convert() being called.
it checks googleapi longitude , latitude of given address , sets (normally hidden) 2 fields found values.
after form submits, throws out values being set. split moment, before submits takes place, see fields being set right values, , after submit values gone.
its hard explain how know that, because html it's being handled sort of asp-solution, remembers values of field , holds on it. in example, if remove submit button , replace non submit element, after click script works , fields being set.
so why, values of field not being submitted server?
again, values set first, , than, form being sumbitted.
best regards, simon
<script type="text/javascript" src="http://maps.google.com/maps/api/js?key=aizasybw2vzup4f6ykbp-bdoneuedgpfhv8mpfm"></script> <script type="text/javascript"> function convert(){ var geocoder = new google.maps.geocoder(); var address=ftform.address.value;geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { var latitude = results[0].geometry.location.lat(); var longitude = results[0].geometry.location.lng(); ftform.latitude.value = latitude;ftform.longitude.value = longitude;} }); } </script> <form method="post" name="ftform"> lat<input type="text" name="latitude" value=""><br> long<input type="text" name="longitude" value=""><br> <br><br><br><input type="text" name="address" value="norway"> <button onclick="convert();">submit</button></form>
Comments
Post a Comment