SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jul 2001
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem Modifying Select Options

    I have two selects in a form on this page http://www.himalayaninstitute.org/dslregister.html.

    The options of the second select are dictated by the first select. In other words. . .the first select has states, and the second has cities. When you change the first select, the second one needs to change so it has the appropriate cities for the state.

    Here is how I am trying to do it. . .
    <script language="JavaScript">
    <!--
    //initialize arrays of cities
    var PA = new Array("Allentown", "Philadelphia", "Pittsburgh", "Wilkes Barre");
    var MI = new Array("Ann Arbor", "Flint", "Kalamazoo");
    var GA = new Array("Atlanta");
    var TX = new Array("Austin", "Dallas", "Houston");
    var LA = new Array("Baton Rouge", "New Orleans");
    var NY = new Array("Binghampton", "Brooklyn", "Buffalo", "Ithaca", "New York", "Olean", "Queens", "Rochester", "Syracuse", "Westchester");
    var FL = new Array("Boca Raton", "Jacksonville", "Miami", "Naples", "Sarasota", "Tampa");
    var MA = new Array("Boston", "Worchester");
    var CO = new Array("Boulder", "Denver");
    var IL = new Array("Chicago");
    var OH = new Array("Columbus");
    var WI = new Array("Fon du Lac", "Green Bay", "Madison", "Milwaukee");
    var CT = new Array("Hartford");
    var IN = new Array("Indianapolis");
    var CA = new Array("Los Angeles", "San Fransisco");
    var MN = new Array("Minneapolis");
    var NE = new Array("Omaha");
    var NJ = new Array("Parsippany", "Princeton");
    var MN = new Array("Minneapolis");
    var OR = new Array("Portland");
    var WA = new Array("Seattle");
    var AZ = new Array("Tuscon");
    var DC = new Array("Washington, D.C.");

    function swapEvents(selectedState) {
    events = eval(selectedState);
    setEvents(window.document.register.events, events);
    }

    function setEvents(eventSelect, events) {
    for (loop = 0; loop < eventSelect.options.length; loop++) { //clears array
    eventSelect.options[loop] = null;
    }
    for (loop = 0; loop < events.length; loop++) { //creates the new options
    eventSelect.options[eventSelect.options.length]= new Option(events[loop]);
    }
    }
    // -->
    </script>
    <select name="eventState" onChange="swapEvents(window.document.register.eventState.options[window.document.register.eventState.selectedIndex].value)">;
    <option value="AZ" selected>Arizona</option><option value="CA">California</option><option value="CO">Colorado</option><option value="CT">Connecticut</option><option value="DC">District of Columbia</option><option value="FL">Florida</option><option value="GA">Georgia</option><option value="IL">Illinois</option><option value="IN">Indiana</option><option value="LA">Lousiana</option><option value="MA">Massachusetts</option><option value="MI">Michigan</option><option value="MN">Minnesota</option><option value="NE">Nebraska</option><option value="NY">New York</option><option value="OH">Ohio</option><option value="OR">Oregon</option><option value="PA">Pennsylvania</option><option value="TX">Texas</option><option value="WA">Washington</option><option value="WI">Wisconsin</option></select>
    <select name="events">
    <option>Tuscon</option>
    </select>

    It is almost working, but it does not leaves some of the cities in the city select after changing it. I.E. selecting New York and then selecting Ohio will produce 7 cities. . . .only one of which is in the Ohio list.

    If anybody has ANY ideas, it would be tremendously appreciated!

  2. #2
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check out this link (View Source)

    Dynamic Drop Down List

  3. #3
    SitePoint Member
    Join Date
    Jul 2001
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    moospot, the 2nd select in that example always has 8 options. How would you do it if the number of options varried? I don't think you can just modify the text property.

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    northern Maine
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.wsabstract.com/script/cut183.shtml

    I think that suits your purpose.
    Jason - Contact Me
    Supermoderator @ CodingForums


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
  •