I need to show/hide options on one select drop down dependant on another select drop down options.
The code below shows what I am trying to achieve.
If the ‘column_select’ select menu option is set to ‘1 column’ then the ‘layout_select’ select menu must display only the ‘none’ option.
If the ‘column_select’ select menu option is set to ‘2 column’ then the ‘layout_select’ select menu must display only the ‘layout 1’ and ‘layout 2’ options.
If the ‘column_select’ select menu option is set to ‘3 column’ then the ‘layout_select’ select menu must display only the ‘layout 3’, ‘layout 4’ and ‘layout 5’ options.
<select name="column_select" id="column_select">
<option value="col1">1 column</option>
<option value="col2">2 column</option>
<option value="col3">3 column</option>
</select>
<select name="layout_select" id="layout_select">
<!--Below shows when '1 column' is selected is hidden otherwise-->
<option value="col1">none</option>
<!--Below shows when '2 column' is selected is hidden otherwise-->
<option value="col2_ms">layout 1</option>
<option value="col2_sm">layout 2</option>
<!--Below shows when '3 column' is selected is hidden otherwise-->
<option value="col3_mss">layout 3</option>
<option value="col3_ssm">layout 4</option>
<option value="col3_sms">layout 5</option>
</select>
So far everything I have tried has failed abysmally…. I am new to jQuery. If anybody could please help it would be much appreciated. Thanks!
Try –
If you were going to use this solution you’d need to hide all of the elements apart from the one with the ‘none’ value in your document.ready function –
Demo – http://jsfiddle.net/Mxkfr/2
EDIT
I might have got a bit carried away with this, but here’s a further example that uses a cache of the original select list options to ensure that the ‘layout_select’ list is completely reset/cleared (including the ‘none’ option) after the ‘column_select’ list is changed –
Demo – http://jsfiddle.net/N7Xpb/1/