1

The following code is JavaScript in a JSP. I want to store the user’s latitude and longitude locations in a MySQL database by setting the value of two hidden fields on the HTML (called “latitude” and “longitude”). However, when the parameters "latitude" and "longitude" are sent to the database, they are null! Why doesn’t this code work? Any help would be greatly appreciated!

//in my onSubmit() JavaScript function 
latitude = position.coords.latitude;
longitude = position.coords.longitude;
document.getElementById("latitude").value = String(latitude);
document.getElementById("longitude").value = String(longitude);
document.getElementById("study_session_form").action = "CreateStudySessionServlet";
document.getElementById("study_session_form").submit();

//in my HTML
<td><input type="hidden" id="latitude" /></td>                   
<td><input type="hidden" id="longitude" /></td>
<td><button id="submit_button” onclick="onSubmit();">Submit</button></td>
1
  • 1
    have you tried by using parseFloat(latitude) ? And the ìnput` field needs a name attribute to get to the value using post. Commented Apr 8, 2013 at 6:39

1 Answer 1

6

you need to set name attribute, ID's are not sent during form submission. E.g.

<input type="hidden" id="longitude" name="longitude" />
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! As you can probably tell I'm still new to this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.