Thursday, July 28, 2005 4:20 PM
triplez
QueryString in JavaScript
JavaScript doesn't have anything to get back the querystring from the url, so here's a source code that works perfectly to get the querystring.
"javascript">
//This is the script to take querystrings from the URL and convert them
//into a Javascript array. "?search=whatever" becomes querystring["search"]
//this loads the portion of the url containing the querystring, and also
//decodes any special character codes
var que = unescape(location.search) ;
//remove the ? from the beginning of the string
var que = que.substring(1, que.length);
//detects multiple values and splits them into an array que[0], que[1] etc
var que = que.split("&");
// creates the querystring array
var querystring = new Array();
//(for some strange reason the "for/next" loop wasn't working)
var loop = 0;
//This loop takes each value in the que array then seperates the "names"
//from the "values" by splitting it into "inter" arrays. the name becomes
// "inter3" and the value becomes "inter2". querystring then loads the
// "inter2" value into a slot called "inter3"
while (loop "=");
var inter2 = inter[1];
var inter3 = inter[0]
que[loop] = inter2;
querystring[inter3] = inter2
loop = loop + 1;
} ;
//(C) Samuel Loy
// --!>
Filed under: Web Development