Getting Query String Values In JavaScript

Getting Query String Values In JavaScript.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <title>Parsing URL Query String In Javascript</title>

    <script type="text/javascript">

    // Build an empty URL structure in which we will store
    // the individual query values by key.
    var objURL = new Object();

    // Use the String::replace method to iterate over each
    // name-value pair in the query string.
    // gives us the query string (if it exists).
    new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),

    // For each matched query string pair, add that
    // pair to the URL struct using the pre-equals
    // value as the key.
    function( $0, $1, $2, $3 ){
    objURL[ $1 ] = $3;


    <script type="text/javascript">

    // Loop over the URL values that we collected.
    for (var strKey in objURL){

    // Output the key to the document.
    "<strong>" + strKey + ":</strong> "

    // Output the value stored at that key.
    objURL[ strKey ] + "<br />"


    <span id="database"></span>

    <script type="text/javascript">

    // Now that the most of the document is loaded, we
    // can reach into the DOM and set values on specific
    // node elements. Let's set the Database node.
    var objNode = document.getElementById( "database" );

    // Check to make sure we have a valid node and that
    // our URL does indeed contain the proper variable.
    if (objNode && objURL[ "i" ]){

    // Set the inner HTML to reflect the value of
    // the database that was sent in the URL.
    objNode.innerHTML = objURL[ "i" ];



This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Getting Query String Values In JavaScript

  1. RG says:

    function OnDivScroll()
    var content = document.getElementById(”);
    if(content.scrollTop < content.scrollHeight – 500)

    CountryWS.GetMoreCountriesObject(pageIndex, pageSize, HandleRetrievedData );

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s