Query String

The query string format is an internet standard. It is a set of characters input to a Web browser and sent to a query program to retrieve specific information from Server side. Query strings typically contain & , ? and = characters.

A typical URL containing a query string is as follows:

http://mysite.com?day=sunday&month=january

Query String Parameters

The query string format is made up of a series of name-value pairs. Within each pair, the field name and value are separated by an equals sign, ‘=’. The series of pairs is separated by the ampersand, ‘ & ‘. In the above case there are two parameters in the querystring- day=sunday and month=january.

There are many ways to get the query string values (field-value pairs) out of the URL of the current page. The following JavaScript program shows how to parse a querystring and retrieve the values from the request.

In the above function, the function getQueryVal accept two parameters. The field name and the URL.

Usage :

getQueryVal('day','http://mysite.com&day=sunday&month=january');

The above code will return “sunday”. If you pass parameter “month” instead of “day” then you will get the result as “january”.

Full Source Code: