【问题标题】:Set Form hidden values with Javascript使用 Javascript 设置表单隐藏值
【发布时间】:2013-08-03 18:58:57
【问题描述】:

我在页面加载时调用此函数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)
{

}

之后,我在 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>

在这个函数中,我用用户的当前位置设置了两个隐藏值latitudelongitude。但是在 PHP 表单 POST 上,这两个值没有通过。怎么了?

【问题讨论】:

  • 您是否检查过 DOM 以检查值是否已设置?

标签: php javascript html geolocation


【解决方案1】:

我觉得这两行应该是这样的

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

【讨论】:

    【解决方案2】:

    Hidden Input Values not being passed through form to New URL

    我搜索了一些相关文章,发现这篇文章最相关。检查并告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-07
      • 1970-01-01
      • 1970-01-01
      • 2018-06-23
      • 2014-06-11
      相关资源
      最近更新 更多