I have the following problem:
I am using the following function to retrieve the GET Parameters of an URL.
$(document).ready(function() {
function getParam(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for ( var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
return ("");
}
});
For example I have the URL http://example.com/?radius=5&lat=31.312 and I want to have the value of "radius"
var radius = getParam("radius");
Problem: In the URL I can see that radius has the value "5" but when I run console.log("radius " + radius);
only after refreshing the browser page the value is shown correctly.
Why isn't the value retrieved correctly while loading the page on the first time? Does anybody has an idea for fixing this?
I am getting the parameters by a submitted form from another html and I want to use them on the current html