home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nintendo GameCube Preview CD-ROM
/
NINTENDOGAMECUBE.iso
/
site
/
js
/
query.js
< prev
next >
Wrap
Text File
|
2001-06-04
|
1KB
|
31 lines
// Build an associative array with all name and value pairs in a 'get' query string
function getSearchAsArray() {
var searchQuery = new Array;
var pair;
var temp;
var search = location.search;
// replace all '+'s with ' 's because unescape() doesn't do it
search = search.replace(/\+/g, ' ');
// for each pair, separate, unescape and place into the associate array
var split = 1;
while (split > 0) {
split = search.lastIndexOf('&');
if (split == -1) split = 0;
pair = search.substring(split + 1, search.length);
// multiple select values should be placed in an array
if (searchQuery[unescape(pair.substring(0, pair.indexOf('=')))] != null) {
temp = searchQuery[unescape(pair.substring(0, pair.indexOf('=')))];
searchQuery[unescape(pair.substring(0, pair.indexOf('=')))] = new Array(temp, unescape(pair.substring(pair.indexOf('=') + 1)));
}
// all other form elements have a one-to-one name and value relationship
else searchQuery[unescape(pair.substring(0, pair.indexOf('=')))] = unescape(pair.substring(pair.indexOf('=') + 1));
search = search.substring(0, split);
}
return searchQuery;
}