Reputation: 35
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>
Upvotes: 1
Views: 687
Reputation: 19228
you need to set name
attribute, ID's are not sent during form submission. E.g.
<input type="hidden" id="longitude" name="longitude" />
Upvotes: 6