Help please with Javascript and SC8

Can someone please help me, I am NOT proficient in Javascript at all.

I have created a web-app that will run on users phones.
The app has multiple forms
I need to consistently get the users location (long/lat) no matter what form in the app they are in.
I have found some Javascript code that I believe will do what I want (see below)

I have no idea where to place this scripts
I have no idea how to get the long and alt from the Javscript into x2 variables so that I can POST these to my server.

Javascript I found:
[SIZE=16px]var x = document.getElementById(“demo”);
function getLocation() {
if (navigator.geolocation) {
} else {
x.innerHTML = “Geolocation is not supported by this browser.”;
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;