Javascript and Querystring Variables
In web browsers you can access the querystring with client-side JavaScript, but there is no standard way to parse out the name/value pairs. Andrew Urquhart from andrewu.co.uk has come up with a very useful Javascript (CSJSRequestObject) that mimics ASP’s server-side Request.QueryString() command.
Here is how it works:
1. Download CSJSRequestObject.js from http://andrewu.co.uk/tools/request/
2. Upload the script to your site and attach the js to your pages:
3. Now you can access the variables in your querystring – say we are using the following querystring: http://www.yoursite.com/index.php?firstname=Bubba&lastname=Smith
var fname = Request.QueryString("firstname");
alert("Hello " + fname + "!");
The script would return an alert box saying “Hello Bubba!”
This is the most basic of operations for this script. Check out all the capabilities here.
This solution is ok, but some years have passed and my preferred method now is to use jQuery. A few examples of how to do this can be found at http://stackoverflow.com/questions/901115/get-querystring-with-jquery