Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

JavaScript
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>
Posted
Updated 26-Feb-13 2:12am
v2
Comments
ZurdoDev 26-Feb-13 7:48am    
Can you be more clear on your scenario and exactly what you are trying to do?
IamBlessed 26-Feb-13 8:12am    
Hi. I have updated the question :)
ZurdoDev 26-Feb-13 8:18am    
I haven't tested this but using jquery I believe you could just do this if you put id="photo" on your form:

$("#photo").attr("action", action + "add in your values here");

This modifies the action attribute of your form.

1 solution

function loc() {
---
}
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900