如何将javascript变量传递给html表单操作标记
我有一个html表单,其中包含名称,经度和纬度文本字段。经度和纬度存储在javascript变量中。你知道如何只将纬度和经度传递给服务器,我的意思是通过网址吗?每次我提交表格时,经度和纬度都不会传入网址?谁能告诉我怎么做?
这是我的javascript和html的代码:
I have an html form which contain name, longitude and latitude text field. The longitude and latitude are stored in a javascript variable. Do you know how pass only the latitude and longitude to a server, I mean via a url? Everytime I am submitting the form, the longitude and latitude are not passed into the url? Can anyone please tell me how to do that?
This is my code for both my javascript and html:
if (navigator.geolocation) {
var geolocation = {};
geolocation.latitude = 0;
geolocation.longitude = 0;
navigator.geolocation.getCurrentPosition(function (p) {
geolocation.latitude = p.coords.latitude;
geolocation.longitude = p.coords.longitude;
}, function (error) {
alert("Failed to get GPS location");
});
} else {
alert("Failed to get GPS working");
}
function loc() {
document.getElementById("longitude").value = geolocation.latitude;
document.getElementById("latitude").value = geolocation.longitude;
}
html:
html:
<form name="photo" method="post" action="url">
<label for="name">Name:</label>
<input type="text" name="name" id="Text1" value="" />
<label for="longitude">Longitude:</label>
<input type="text" name="longitude" id="longitude" />
<label for="latitude">Latitude:</label>
<input type="text" name="latitude" id="latitude" />
<label for="image">Image:</label>
<input type="text" name="image" id="image" />
<input type="submit" value="Submit" />
</form>
function loc() {
---
}
function is there to在textfield中设置值,但你没有调用它。
调用这个loc()函数来设置textfield中的值。
function is there to set the value in textfield, but you did not call it.
call this "loc()" function to set the value in textfield.