Klovera.comBlog
Follow Us:

Javascript and Querystring Variables

Dustin  |  Programming & Scripting  |  November 15th 2007

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.

One Response to “Javascript and Querystring Variables”

  1. Dustin J. Czysz says:

    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

Leave a Reply

Klovera is a forward thinking, full service digital agency whose purpose is to bring value to our client's businesses through creativity, strategy, metrics, user experience and technology.