简体   繁体   English

使用Javascript设置表单隐藏值

[英]Set Form hidden values with Javascript

I am calling this function getLocation() on page load: 我在页面加载时调用此函数getLocation()

<script>
function getLocation()
{
    if (navigator.geolocation)
    {
        navigator.geolocation.getCurrentPosition(showPosition,showError);
    }
}
function showPosition(position)
{
    var latlon=position.coords.latitude+","+position.coords.longitude;
    //alert("Your location: "+latlon);
    document.getElementById("latitude").value = coords.latitude;
    document.getElementById("longitude").value = coords.longitude;
}
function showError(error)
{

}

After that, in HTML I have defined two hidden values: 之后,在HTML中,我定义了两个隐藏值:

<FORM id="myForm" action="insertar.php" method="post" enctype="multipart/form-data" data-ajax="false">
    ....Some other controls...
<input type="hidden" id="latitude" name="latitude" value="">
<input type="hidden" id="longitude" name="longitude" value="">
</FORM>

In this function, I am setting two hidden values latitude and longitude with user's current location. 在此功能中,我将使用用户的当前位置设置两个隐藏值latitudelongitude But on with PHP form POST these two values are not passing. 但是在PHP表单POST上,这两个值没有传递。 Whats wrong? 怎么了?

I think these 2 line should be like this 我认为这两条线应该是这样的

document.getElementById("latitude").value = position.coords.latitude;
document.getElementById("longitude").value = position.coords.longitude;

Hidden Input Values not being passed through form to New URL 隐藏的输入值未通过表单传递到新URL

i searched some of relevant article and found this one most relevant. 我搜索了一些相关的文章,发现这是最相关的。 check and let me know. 检查并让我知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM