Saturday, February 18, 2006
Prototype's parseQuery() extension to String Object
The Prototype Javascript Library 1.4.0 introduces a useful extension to String Object -- String.parseQuery() and its synonym String.toQueryParams()
- It takes a query string, i.e, the part of the url starting with the '?'.
- It can be obtained with the location.search value.
- The name/value pairs are separated with '&'
- Example url: http://www.xltd.com/util/location.htm?foo=bar&name=homer&place=springfield
Example Usage:
var queryString = location.search;
var qryStrKeys = queryString.parseQuery();
alert(qryStrKeys.foo + " " + qryStrKeys.name + " " + qryStrKeys.place);
Result: bar homer springfield
i
Post a Comment