我有包含名字,經度和緯度文本字段的HTML表單。經度和緯度存儲在一個JavaScript變量中。你知道如何發佈名稱,緯度和經度的服務器,我的意思是通過一個網址?每次我提交表單時,經度和緯度都不會傳遞給url?任何人都可以請告訴我該怎麼做?如何對一個JavaScript變量傳遞到HTML表單操作標記
謝謝
這是我爲我的JavaScript和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:
<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>
讓我們來看看窗體的HTML,加上無論你已經有了JavaScript代碼。 – 2013-02-26 11:26:41