|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Hi, I'm trying to make interactive select menus where the user selects an item from a drop down menu and it creates a new dropdown menu dynamically under it.
I don't want it done with innerHTML, so it involves a good deal on nodes and such. And I'm having trouble right at the part where I need to create the 2nd select box with values and the text in them. My test code so far involves selecting a car to purchase. First option would be type of car, and then the second would be price range. Here's my code so far: <!-- var choiceOne; var choiceTwo; var choiceThree; //first selection to determine dropdown menus function firstChoice (selection){ //user does not select if (selection == 1) { alert('Please select the type of car to get started!'); } //user selects "sedan" else if (selection == 2) { choiceOne = "sedan"; choiceSedan2(); } //user selects "SUV" else if (selection == 3) { choiceOne = "SUV"; } } //if user selects "sedan" as the first choice function choiceSedan2() { //creates the select element along with its attributes selectElement=document.createElement('select'); selectElement.setAttribute("name", "dropdown2"); selectElement.setAttribute("id", "dropdown2id"); selectElement.setAttribute("onchange", "alert('it works')"); //creates each option in the select menu optionElement=document.createElement('option'); optionElement.setAttribute("value", "1"); optionElement.setAttribute("label", "Please select your price range"); //here's the trouble spot - what would I have to do to display the text in the select box? selectElement.appendChild(optionElement); document.getElementById('dropSecond').appendChild( selectElement); } //--> </script> Here's the HTML: <form name="shopper" method="POST" action=""><h2> <!-- first dropdown --> <div id="dropFirst"> <select id="dropdown1id" name="dropdown1" onchange="firstChoice(this.options[this.selectedIndex].value)"> <option value="1" selected>Please select the type of vehicle</option> <option value="2">Sedan</option> <option value="3">SUV</option> </select> </div> <!-- 2nd dropdown location --> <div id="dropSecond"> </div> The 2nd dropdown would be created in the dropSecond div. Please help!! Thank you. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Interactive select menus |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|