JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old October 1st, 2004, 12:45 AM
dkc48 dkc48 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 1 dkc48 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Post Interactive select menus

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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Interactive select menus


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway