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) 

{
navigator.geolocation.getCurrentPosition(mostrarUbicacion);
}
else {
alert("?Error! Este navegador no soporta la Geolocalizaci?n.");
}

var_dump(navigator.geolocation.getCurrentPosition(mostrarUbicacion));

function mostrarUbicacion(position)
{

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

}

function refrescarUbicacion()
{
navigator.geolocation.watchPosition(mostrarUbicacion);
}

</script>

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???