PDA

View Full Version : Javascript Query String and Commas



dude9er
07-25-2008, 07:38 PM
I have this JS that pulls the parameters from a query string and places them into the callSearch variable

[code]
<script language="javascript">
var qsParm = new Array();
function qs() {
var query = window.location.search.substring(1);
var parms = query.split('&');
for (var i=0; i<parms.length; i++) {
var pos = parms[i].indexOf('=');
if (pos > 0) {
var key = parms[i].substring(0,pos);
var val = parms[i].substring(pos+1);
qsParm[key] = val;
}
}
}

qs();
var country=qsParm['country'];
var cityList=qsParm['cityList'];
var airport=qsParm['airport'];

callSearch('05664621','','Y','N','N',country,'',cityList,airport,'','#F5F5F5');
</script>

[code]

The URL looks like this:

http://somesite.com/Search_Engine.asp?cityList=PAR,BOD,CCF,CEQ,CQF,FNI,LYN,MRS,NCE,QXB,VRS&country=FRA&airport=JFK

When city list has multiple citys with comma's the JS above does not parse the comma's into the callsearch 'cityList' parameter.

When I limit the cityList parameter to one city like so, it works fine:

http://somesite.com/Search_Engine.asp?cityList=PAR&country=FRA&airport=JFK

Why is this happening? Any help would be great!

Thanks in advance!!!

Dal
07-26-2008, 03:55 AM
Try a different seperator then modify it back to commas if you need to. Im sure Ive seen them in URL's but maybe they are handled differently.

Dal