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>
parseFloat(latitude)? And the ìnput` field needs anameattribute to get to the value using post.