Skip to main content
GameDev.net gamedev.net
🔒 Locked

JScript and dynamic dropdown menu probs

Started by JackRabbit Feb 20, 2003 at 1:41 AM 1 replies 1.8k views
Original Post
JackRabbit
JackRabbit
Ok, im not really sure if this is the proper place to ask this, but here goes: Im trying to create a few dynamic dropdown menus for a webpage, using the SELECT tag. By dynamic i mean that if you select an option in one menu, the list of options in another will change, depending on what you selected. So far, i have made 2 dropdown menus, and when you select and option in the first, the options in the second will change. Here is the code that is supposed to do the job:
function PopulateList() {

    // Rensa the second list of its current options
    for( var i=0;i < selSecondList.options.length; i++)
    {
        selSecondList.remove( i );
    }
    
    // Now, depending on the choice,
    // fill the second list with new options.
    switch ( selFirstList.value )
    {
        case "Choice1":
        {   
            var oOption = document.createElement("OPTION");
            oOption.text = "NewOption";
            oOption.value = oOption.Text;
            selSecondList.add( oOption );
            
        }break;
        
        case "Choice2":
        {
            var oOption = document.createElement("OPTION");
            oOption.text = "NewOption";
            oOption.value = oOption.text;
            selSecondList.add( oOption );
       
        }break;
        
        case "Choice3":
        {
            var oOption1 = document.createElement("OPTION");
            oOption1.text = "NewOption1";
            oOption1.value = oOption1.Text;
            selSecondList.add( oOption1 );
           
            var oOption2 = document.createElement("OPTION");
            oOption2.text = "NewOption2";
            oOption2.value = oOption2.text;
            selSecondList.add( oOption2 );
           
        }break;
    }
}

   
Ok, when i select the first 2 choices in the first list, everything is fine, the second list is updated as expected. However, the problem occurs with the third choice. As you can see in the code, the third choice fills the second list with 2 options, instead of only 1, as the first 2 choices did. Now, when the third choics is selected, the second list is updated just fine, BUT! when i then select either of the first 2 choices, where the list should only contain 1 option, it instead contains 2 ?? I havent got a clue why this happens. Anyone got any idea of what im doing wrong here ? Im sorry if this is a bit confusing, just let me know if i need to clarify anything. Thanks for your time! PS: If your know of any good tutorial site that discusses this, please let me know. Thanks! [edited by - JackRabbit on February 20, 2003 2:50:27 AM]
JackRabbit
JackRabbit
*bump* (again)

Sorry Mods, let me know if im being a bother

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.