Capture javascript variables to form fields.

Hello everyone, I hope someone can help. I have the following code:

<script type=“text/javascript”>

if (navigator.geolocation) 

else {
alert("?Error! Este navegador no soporta la Geolocalizaci?n.");


function mostrarUbicacion(position)

var latitud = position.coords.latitude;
var longitud = position.coords.longitude;
var div = document.getElementById("ubicacion");


function refrescarUbicacion()


with this code what I want is to capture the coordinates of the location of the customer and store them in a Mysql table, for that I have a form to be filled the nombre_ubicacion, Latitude, Longitude fields; with the following lines:

document.F1.dircli_latitud.value = latitud;
document.F1.dircli_longitud.value = longitud;

He had thought of capturing the variables latitude and longitude of javascript to the form fields but have failed to work. What I can do???