if (document.all && window.attachEvent) { window.attachEvent("onload", initialize1); // Non-IE load and unload } else if (window.addEventListener) { window.addEventListener("load", initialize1, false); }function setUserPos(position) { document.getElementById('fromAddress1').value = position.coords.latitude + ', ' + position.coords.longitude; } if(navigator.geolocation) { navigator.geolocation.getCurrentPosition(setUserPos); }