Get QueryString values in JavaScript
Hi,
We can make use of the following functions to get the value of querystring parameters through JavaScript
// helper function to get the query string
function Querystring() {
var querystring = location.search.substring(1, location.search.length);
var args = querystring.split(‘&’);
for (var i = 0; i < args.length; i++) {
var pair = args[i].split(‘=’);
temp = unescape(pair[0]).split(‘+’);
name = temp.join(‘ ‘);
temp = unescape(pair[1]).split(‘+’);
value = temp.join(‘ ‘);
this[name] = value;
}
this.get = Querystring_get;
}
function Querystring_get(strKey, strDefault) {
var value = this[strKey];
if (value == null) {
value = strDefault;
}
return value;
}
Suppose our current page url is
http://mycustompage/home.aspx?id=1020
To get the value for id we’ll do this
var qs = new Querystring();
Bye..
Filed under: JavaScript Tagged: JavaScript
This was originally posted here.

Like
Report
*This post is locked for comments