Click here to Skip to main content
11,922,641 members (56,834 online)
Rate this:
Please Sign up or sign in to vote.
See more: Javascript HTML web-dev
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;


<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" />
Posted 26-Feb-13 2:39am
Edited 26-Feb-13 3:12am
ryanb31 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 :)
ryanb31 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
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151125.1 | Last Updated 26 Feb 2013
Copyright © CodeProject, 1999-2015
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