the_oliver Posted June 22, 2009 Share Posted June 22, 2009 Hi, Appolojies if this is not done through Javascript... I have a drop-down menu, and if a particular option is chosen i need another to apper. For any other options the second drop down box should remain hidden. Could any one suggest how i would best go about this or perhaps point me in the direction of a tutorial? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/163275-drop-down-menu-appear/ Share on other sites More sharing options...
Ken2k7 Posted June 23, 2009 Share Posted June 23, 2009 Use an onchange function. Example - <select id='e' onchange='foo(this);'> <option value='a'>a</option> <option value='b'>b</option> <option value='c'>c</option> <option value='d'>d</option> <option value='e'>e</option> </select> <select id='k' style='display: none;'> <option value='a'>a</option> <option value='b'>b</option> <option value='c'>c</option> <option value='d'>d</option> <option value='e'>e</option> </select> <script type='text/javascript'> function foo (e) { var idx = e.options.selectedIndex; if (e.options[idx].value === 'e') document.getElementById('k').style.display = ''; } </script> Quote Link to comment https://forums.phpfreaks.com/topic/163275-drop-down-menu-appear/#findComment-861668 Share on other sites More sharing options...
Psycho Posted June 23, 2009 Share Posted June 23, 2009 That IF statement needs an else - otherwise the display will never return to hidden. I'd use the ternary operator in this situation. function foo (e) { var idx = e.options.selectedIndex; document.getElementById('k').style.display = (e.options[idx].value === 'e') '' : 'hidden'; } Quote Link to comment https://forums.phpfreaks.com/topic/163275-drop-down-menu-appear/#findComment-861701 Share on other sites More sharing options...
Ken2k7 Posted June 24, 2009 Share Posted June 24, 2009 I think hidden should be none, but good save mjdamato. Quote Link to comment https://forums.phpfreaks.com/topic/163275-drop-down-menu-appear/#findComment-862454 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.