Forum Moderators: open
I need to duplicate a PHP function in JS to change a pages display based on the value of a var, and it has to be done client side on a local drive.
The string would be simple like: page.htm?a=1
I need to get the value of "a"
Any ideas?
dhdweb
fullURL = parent.document.URL
xxx = fullURL.substring(fullURL.indexOf('?')+3, fullURL.length)
It says to "Take the text string of the URL. Use a substring beginning three past the position of the "?" and going through the end of the text string.
Using the following script:
function getArgs() {
var args = new Object();
var query = location.search.substring(1);
var pairs = query.split("&");
for(var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf('=');
if (pos == -1) continue;
var argname = pairs[i].substring(0,pos);
var value = pairs[i].substring(pos+1);
args[argname] = unescape(value);
}
return args;
}
var args = getArgs();
if (args.a) a = parseInt(args.a);
document.write(a);
If the query is "?a=01" thru "?a=07" the output is 1 thru 7
But, (this is the killer!)
If the query is "?a=08" or "?a=09" the output is 0
Please help!
dhdweb