Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Modify a double drop menu to a triple

  1. #1
    Join Date
    Aug 2010
    Location
    Vancouver, Canada
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Modify a double drop menu to a triple

    I am presently using a script provided by http://javascript.internet.com/forms...drop-down.html. This script works great, however I need three sequential drop down menus rather than the two provided in this script. I need Country > Province/State > Cities. Unfortunately I am not a programmer, but generally muddle along to a resolution. In this case I am stumped. Can anyone show me what needs to be added to that existing script to convert it into a three menu script instead of two? I apologize in advance for my lack of scripting knowledge, but much of JavaScript leaves me thoroughly confused.

  2. #2
    Join Date
    Aug 2010
    Posts
    7
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default

    This is not necessarily the best method, but I've attached a modified version of the code to this message. It is formatted slightly differently, but I hope it should be clear what to do.

    Make sure you:
    1. Adjust the function "populateState" to what is in the attachment. (I would just copy and paste the whole function, because one of the changes is hard to see).
    2. Adjust the function "initCountry" to what is in the attachment.
    3. Create the function "populateCity" written in the attachment.
    4. Adjust the HTML section to what is written in the attachment.
    5. Include the value for the variable "city" at the top of the file. (It gives examples of how to use it for a country with a state and one without).

    I think that is all you have to do. I hope it does what you want.

  3. The Following User Says Thank You to deathsandwich For This Useful Post:

    Gregoriochavez (08-21-2010)

  4. #3
    Join Date
    Aug 2010
    Location
    Vancouver, Canada
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs up Looks good

    Thanks for that script. I've downloaded it and had a very quick look, and it looks like it might work. Let me get back to you in the next day or so when I've had time to try it. Thanks again.

  5. #4
    Join Date
    Aug 2010
    Location
    Vancouver, Canada
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Quick question about the cities list of names. Does that require the Country code and the State code in front of each city name? i.e. CA:BC:Vancouver

  6. #5
    Join Date
    Aug 2010
    Posts
    7
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default

    It works in two ways. If a state has been selected then it will look for cities with the word "STATE" before them, with both the country code and state code. If there are no available states to be selected it will look for the word "COUNTRY" and show cities from the entire country, requiring the country code.

    Here are two examples:

    STATE:UK:GLONDON:LONDON:London
    COUNTRY:GB:LONDON:London

    The first one has "STATE" before it, and so requires both the country "UK" and the state "GLONDON" to be selected before the city London is displayed as an option.

    The second one has "COUNTRY" before it, and so requires only the country "GB" to be selected. This way, if there are no states available to be selected the city can be given as an option anyway.

    The main issue in my opinion is that, at the moment, if a state can be selected then one MUST be selected before a city can be selected. I could change the code to allow a city to be selected even if a state could be selected, but has not been chosen yet. Of course, you can write in the city within the text box that appears anyway. I wasn't sure what was best, so please just say.
    Last edited by deathsandwich; 08-21-2010 at 08:46 PM.

  7. #6
    Join Date
    Aug 2010
    Location
    Vancouver, Canada
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    My confusion lies with two words. You are saying COUNTRY and you are saying COUNTY. I am not sure if this is a misspelling or if both words are used but in different places. In your reply you show an example as COUNTRY:GB:LONDON:London but refer to it as, quote "The second one has "COUNTY" before it..." end quote.

    On the other point, I prefer it the way it is where the user MUST select a Country first, MUST then select a State within that Country, and then the preferred City within that State.

  8. #7
    Join Date
    Aug 2010
    Posts
    7
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default

    Ooops! Sorry, that was a very unfortunate typo! I meant COUNTRY in both cases.

  9. #8
    Join Date
    Aug 2010
    Location
    Vancouver, Canada
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the clarification, and now things make sense. The site is slowly coming together, and my main remaining challenge is to start entering City names. Out of curiosity I selected a Country and a State, and then tried to enter a City name in the City select box, but no joy. So, back to using the old quill pen. {;-)

    I sincerely want to thank you for your help. It's nice to know that there are people out there who are willing to share their knowledge so as to help those less knowledgeable. Now, if you ever want to set up an offshore company...

    Gordon

  10. #9
    Join Date
    Aug 2010
    Location
    Vancouver, Canada
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I now have the entire code working as it should, with one exception. I have entered two cities here in my province, to test that I am doing the database entries correctly. From my perspective I have entered them exactly the same as you did in your samples. Ergo:

    var city = '\
    STATE:UK:GLONDON:LONDON:London|\
    COUNTRY:GB:LONDON:London|\
    STATE:CA:BC:Vancouver|\
    STATE:CA:BC:Victoria|\
    ';

    When I click on Select City after selecting CA and BC for my Country and State, I get 'undefined' for each of my entries, whilst your's show up. And yes, I have placed var postCity = ''; where it belongs. How have I screwed up this time?

  11. #10
    Join Date
    Aug 2010
    Posts
    7
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default

    I think you meant something like this:

    STATE:CA:BC:VANCOUVER:Vancouver|\
    STATE:CA:BC:VICTORIA:Victoria|\

    In your example, you did not enter a city code as well as the city name. So the format of the STATE type is:

    STATE:countrycode:statecode:citycode:cityname

    And for the COUNTRY type it is:

    COUNTRY:countrycode:citycode:cityname

    The city code can be anything, so probably just a shortened name for the city would be best (rather than an actual code). Ive tried that and it works for me.
    Thanks for your reply! I'll be sure to contact you if I need help setting up an offshore company in the future.

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
  •