Jim Rogers

Lives in Baton Rouge, LA, with two dogs, one cat, and one lovely wife. I'm a lead developer for GCR & Associates.

Katrin and Jim

Month List

Javascript Query String Parse

by Jim Jan 30, 2007 2:38 PM

This shouldn't be so hard to google. To parse an html page's query string with Javascript, using a regular expression:

// Get the value of one of the arguments in the query string
function getFieldValue(name)
{
    var match = (new RegExp('[?&;]' + name + '=([^&;#]*)')).exec(location.search);
    return match ? unescape(match[1]) : "";
}

Returns an empty string if the name doesn't match.

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading