Name

ParseQueryString v1.0.2

Synopsis

<script type="text/javascript" src="ParseQueryString.js"></script>

<script type="text/javascript">

var pqs = new ParseQueryString();

alert( pqs.param("name") );
alert( pqs.params("hobbies") );

</script>

Description

Processes the query component of the parent window's URI, and provides a programmer's interface to the query variables. The query string is assumed to be correctly encoded with the application/x-www-form-urlencoded content type.

Methods

ParseQueryString()

Object constructor.

var pqs = new ParseQueryString();
param( [ name ] )

Returns the string value associated with name (name is case sensitive). If name is not defined in the query string, returns undefined. If multiple values are associated with name, returns the first value from the order that it occurs in the query string.

If name is omitted, returns the next name from the query string, so that you can iterate over it. When all names have been read, the undefined value is returned (which when evaluated in boolean context produces a false value).

/* e.g., name=Smith&hobbies=Racquetball&hobbies=White+water+rafting */

pqs.param("name")     /* returns "Smith" */
pqs.param("hobbies")  /* returns "Racquetball" */
pqs.param("age")      /* returns undefined */

/* iterate over all names in the query string */
/* alerts "name" and "hobbies" */
while (p = pqs.param())
    alert(p);
params( [ name ] )

Returns an array of all values associated with name (name is case sensitive). If name is not defined in the query string, returns null.

If name is omitted, returns an array of every name in the query string.

/* e.g., name=Smith&hobbies=Racquetball&hobbies=White+water+rafting */

pqs.params("name")     /* returns ["Smith"] */
pqs.params("hobbies")  /* returns ["Racquetball", "White water rafting"] */
pqs.params("age")      /* returns null */
pqs.params()           /* returns ["name", "hobbies"] */

Notes

Following the W3C recommendation, this implementation supports the use of ";" in place of "&" to save authors the trouble of escaping "&" characters in anchor-style links.

This software defines a clone method for the Array and Object classes as well as a decodeURL method for the String class.

Credits

Author

Jeff Mott <mjeff1@twcny.rr.com>

Copyright © 2004-2005, Jeff Mott. All rights reserved.
This is free documentation; you can redistribute it and/or modify it under the terms of the GNU Free Documentation License.