开发者

How to put JavaScript values as hidden form fields?

开发者 https://www.devze.com 2023-02-17 05:36 出处:网络
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.

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号