Thursday, 2 December 2010

Reading Querystring value using JavaScript

The following function can be used to read the value of given key from querystring.

/* function to read value of the given key
, x, from querystring */
function GetQStringVal(x) {

var a = location.search.substring(1);
var b = a.split("&");

for (var i = 0; i < b.length; i++) {

var c = b[i].split("=");
if (c[0].toLowerCase() == x.toLowerCase())
{
return c[1];
}
}
return "";
}

No comments:

Post a Comment