How to put JavaScript values as hidden form fields?
I have a google map that has a marker which is dragged. When I get the new latitude and lo开发者_开发百科ngitude coordinates, I need to put them into an HTML form as hidden fields.
How can I do that? The example page with current code is here: http://www.comehike.com/outdoors/parks/add_trailhead.php
If your form already contains the hidden input fields and those fields have IDs, you can do
document.getElementById("id of the input field").value = myVariable;
Add these to your form (if they dont exist):
<input type="hidden" value="" id="lat" name="lat" />
<input type="hidden" value="" id="lng" name="lng" />
Then once you want to update the values just do:
document.getElementById("lat").setAttribute("value", newLat);
document.getElementById("lng").setAttribute("value", newLng);
精彩评论