JQuery Plugin: ParseQuery

When the time comes to grab and parse some values from the QueryString in JavaScript, it can be as simple as one line of code with this nice, compact JQuery plugin called PARSEQUERY.

ParseQuery Download Site: http://plugins.jquery.com/project/parseQuery

Essentially this little plugin turns the query string into a JavaScript object as follows:

URL: www.somelink.com/test.php?Cat=test&Value=hello

  1. var query = $.parseQuery();
  2. alert(query.Cat);
  3. alert(query.Value);

And thats it. Now you have your QueryString in a tightly wrapped object. You may have to test whether a particular property exists on the created object (i.e. Make sure what your expecting is provided in the object):

  1. if ($.isEmptyObject(query.Cat)) {
  2.      query.Cat = ‘some default value’;
  3. }

It is important to note, this component was not developed on the latest release of JQuery. I have tested its use in JQuery 1.4.2 – no issues found.

Leave a Reply