SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    canada
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript Query String and Commas

    I have this JS that pulls the parameters from a query string and places them into the callSearch variable


    <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>



    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!!!

  2. #2
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Replace:
    Code:
    var cityList=qsParm['cityList'];
    with

    Code:
    var cityList=qsParm['cityList'].split(',');
    This code will convert qsParm['cityList'] to array by splitting it by the , character.
    I'm creating trouble-free Apache, PHP, MySQL installer, WITSuite,
    and use it to setup my development environment.
    Demo, support, contact. Questions?

  3. #3
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    canada
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    alex.w747, thanks for teh response. Unfortunately the code isn't working right. Any ideas?
    http://www.members-only-travel.com/M...RA&airport=JFK

    the final callSearch code is suppose to look like this

    callSearch('05664621','','Y','N','N',country,'','PAR,BOD,CCF,CEQ,CQF,FNI,LYN,MRS,NCE,QXB,VRS',airport,'','#F5F5F5');

    Is this how the JS modification you made will parse?

  4. #4
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then you do not need any parsing. It already works that way.

    BTW, as I see, the callSearch just does not support multiple destinations.
    I'm creating trouble-free Apache, PHP, MySQL installer, WITSuite,
    and use it to setup my development environment.
    Demo, support, contact. Questions?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •