Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Country-state selector - need it to POST different values (numbers) than the text....

    Hi all...

    I'm struggling with a little problem at the moment. I'm creating a subscription page for a mailing list on my site. It's got a country-state selector on it - the state field is auto-populated with states depending on the country selected.

    The form submits to my PHPlist submissions page A-ok. The only problem is, PHPlist stores values as numbers (you know, the good old:

    <option value="1">Afghanistan</option>
    <option value="2">Albania</option>
    <option value="3">Algeria</option>

    etc. etc.

    Problem is, the script I've found for the country-state selector uses a string and the "split" command. Therefore the form is set up so the values are the actual country names rather than numbers.

    Is there any way to modify the form so it will POST numbers to the PHP form, but not display those numbers in the text box (i.e. only display the country and state names?).

    I started adding numbers to the beginning of each entry (and it seems to work), but it isn't a very elegant solution, especially when it comes to states (over 4000!!!). It also means users can't type in the first letter to get to the letter of their country, since the entries would be starting with numbers....

    Here's the page I've put together: www.thesunpilots.com/list2.html (the first 150 entries have had numbers added to the front of the text)

    and here's the PHPlist form it's submitting to:
    http://thesunpilots.com/phplist/?p=subscribe&id=1





    Before anyone asks why I'm not using the PHPlist form's code, it's because I don't want users to have to sort through 4000 states - I want only the states for their selected country to be displayed.

    Help!! And thanks again,
    Raj

  • #2
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it is actually a very simple fix.

    Option((object)text, (object)value) has two overloads: the node text, and the node value.

    currently it's:
    for(i=0;i<sStateArray[cboCountry.selectedIndex].split("|").length;i++){
    sState = sStateArray[cboCountry.selectedIndex].split("|")[i];

    if(sDefaultState == sState) {
    sDefault=true;
    if (navigator.appName=="Microsoft Internet Explorer"){cboState.focus();}
    }
    else {sDefault=false;}

    if(sDefault) {cboState.options[i]=new Option(sState,sState,sDefault,sDefault)}
    else {cboState.options[i]=new Option(sState,sState);}
    }

    what your asking for would mean you need to change that loop too.

    for(i=0;i<sStateArray[cboCountry.selectedIndex].split("|").length;i++){
    sState = sStateArray[cboCountry.selectedIndex].split("|")[i];

    if(sDefaultState == sState) {
    sDefault=true;
    if (navigator.appName=="Microsoft Internet Explorer"){cboState.focus();}
    }
    else {sDefault=false;}

    if(sDefault) {cboState.options[i]=new Option(sState,sState,sDefault,sDefault)}
    else {cboState.options[i]=new Option(sState,i);}
    }
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<


  •  

    Posting Permissions

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