I am trying to create three drop down menus (a list of activity choices), for a person to show top three preferences. I would like to have the second and third menus automatically remove the previously selected choices as options. I have only programmed in the three identical drop down menus:
<div id="satellites">
<p><b>Satellite Choices</b><br />
List your first, second, and third choices. You will be given your first choice if it is not full. ALL events have limited capacity. If you do not choose a satellite, one will be assigned for you.<br />
<label>First Choice*: </label><select name="satellite1 id="firstchoice" required="required""><br />
<option value="art"/>Art</option><br />
<option value="basketball"/>Basketball</option><br />
<option value="dance"/>Dance</option><br />
<option value="drama"/>Drama</option><br />
<option value="missions"/>Missions</option><br />
<option value="photo1"/>Beginning Photography</option><br />
<option value="photo2"/>Advanced Photography</option><br />
<option value="rock_climbing"/>Rock Climbing</option><br />
<option value="scrap-booking"/>Scrap-Booking</option><br />
<option value="sgjr"/>Summer Games Jr. Training</option><br />
<option value="soccer"/>Soccer</option><br />
<option value="technology"/>Technology</option><br />
<option value="ultimate"/>Ultimate Frisbee</option><br />
<option value="video_games"/>Video Games</option><br />
<option value="volleyball"/>Volleyball</option><br />
<option value="water_park"/>Water Park</option><br />
</select><br /><br />
<label>Second Choice*: </label><select name="satellite2" id="secondchoice" required="required"><br />
<option value="art"/>Art</option><br />
<option value="basketball"/>Basketball</option><br />
<option value="dance"/>Dance</option><br />
<option value="drama"/>Drama</option><br />
<option value="missions"/>Missions</option><br />
<option value="photo1"/>Beginning Photography</option><br />
<option value="photo2"/>Advanced Photography</option><br />
<option value="rock_climbing"/>Rock Climbing</option><br />
<option value="scrap-booking"/>Scrap-Booking</option><br />
<option value="sgjr"/>Summer Games Jr. Training</option><br />
<option value="soccer"/>Soccer</option><br />
<option value="technology"/>Technology</option><br />
<option value="ultimate"/>Ultimate Frisbee</option><br />
<option value="video_games"/>Video Games</option><br />
<option value="volleyball"/>Volleyball</option><br />
<option value="water_park"/>Water Park</option><br />
</select><br /><br />
<label>Third Choice*: </label><select name="satellite3" id="thirdchoice" required="required"><br />
<option value="art"/>Art</option><br />
<option value="basketball"/>Basketball</option><br />
<option value="dance"/>Dance</option><br />
<option value="drama"/>Drama</option><br />
<option value="missions"/>Missions</option><br />
<option value="photo1"/>Beginning Photography</option><br />
<option value="photo2"/>Advanced Photography</option><br />
<option value="rock_climbing"/>Rock Climbing</option><br />
<option value="scrap-booking"/>Scrap-Booking</option><br />
<option value="sgjr"/>Summer Games Jr. Training</option><br />
<option value="soccer"/>Soccer</option><br />
<option value="technology"/>Technology</option><br />
<option value="ultimate"/>Ultimate Frisbee</option><br />
<option value="video_games"/>Video Games</option><br />
<option value="volleyball"/>Volleyball</option><br />
option value="water_park"/>Water Park</option><br />
</select><br /><br />
</div>
How would I go about this? I am assuming I would need to use javascript, but I have no idea where to start.
There’s a lot wrong with your markup.
You can’t have any other elements inside a select, so get rid of the line breaks. Also, option is not self closing, and you can’t do
/>AND provide the closing tag.. that makes no sense.So each line should change from:
to:
You also have mismatched quotes in the first select:
Should be
Run your markup through Markup Validator to catch these things.
To clear the other selects based on the first one, you can bind to its
onchangeevent.Then in
clearothers()you set their option’s selectedIndex to a default value:I would also add a disabled “Select an option” option to each:
Put it all together and you get something like this demo.
To remove specific items from selects based on previous selection, you can use code similar to below:
Of course, you’ll need some logic to bring those values back once the selection changes to something else.
Demo