Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:
 
<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 26-Feb-13 2:39am
Edited 26-Feb-13 3:12am
v2
Comments
ryanb31 at 26-Feb-13 7:48am
   
Can you be more clear on your scenario and exactly what you are trying to do?
IamBlessed at 26-Feb-13 8:12am
   
Hi. I have updated the question :)
ryanb31 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 285
1 DamithSL 265
2 CPallini 195
3 Maciej Los 175
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 26 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100