Reading query parameters using Java Script


One of the best mechanism passing data between pages is query strings in the URL. As we know server side scripts like JSP,SERVLETS,ASP,PHP supports very easy way to parse query paremeters,

But  Java script being a client side script also supports a very easy way to parse the query parameters in the URL.

Use the below method and see the how easy we achived.


var url = window.location.toString(); // read the URL
var prms = RegExp.$1;

var prms = prms.split(“&”); //SPLIT THE VALUES IN ARRAY
var stringList = {};

for(var i=0;i<prms.length;i++){
var tmpKey = prms[i].split(“=”);
stringList[tmpKey[0]] = unescape(tmpKey[1]);

for(var j in stringList){
document.write(j+” = “+stringList[j]+”<br/>”);


R Vashi

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.