Home > JScript > Reading Querystring using Jscript

Reading Querystring using Jscript


Below is the Jscript function to parse query string (i.e., In to Parameter & Value pair)

// Read querystring and returns Parameter & Value pair Array

function fetchQueryStringParams() {

var qrStr =;

var spQrStr = qrStr.substring(1);

var arrQrStr = new Array();

// splits each of pair

var arr = spQrStr.split(‘&’);

for (var i = 0; i < arr.length; i++) {

// splits each of field-value pair

var index = arr[i].indexOf(‘=’);

var key = arr[i].substring(0, index);

var val = arr[i].substring(index + 1);

// saves each of field-value pair in an array variable

arrQrStr[key] = val;


return arrQrStr;


How do I call this method?

function onload() {

var arrQrStr = fetchQueryStringParams();

alert(“First Name” + arrQrStr[‘fname’]);

alert(“Last Name” + arrQrStr[‘lname’]);


Hope it helps 🙂

  1. No comments yet.
  1. July 11, 2012 at 11:57 AM

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: