c_pattle Posted May 22, 2010 Share Posted May 22, 2010 Hey I have a form on my website with a select box. What I want to achieve is depending on what the user selects from this select box another select box will appear. For example if the users selects either option 1, 3, or 6 from the first select menu a second one will appear. Is this possible to do using PHP as I'm not sure how to do it. Thanks Quote Link to comment Share on other sites More sharing options...
-Karl- Posted May 22, 2010 Share Posted May 22, 2010 Search google for chained select boxes. Quote Link to comment Share on other sites More sharing options...
Rustywolf Posted May 22, 2010 Share Posted May 22, 2010 or try using a switch statement Quote Link to comment Share on other sites More sharing options...
leehanken Posted May 22, 2010 Share Posted May 22, 2010 This could be done with html and javascript and no php as the behaviour is on the client side. For example: <script language='javascript'> function list1change() { div1 = document.getElementById('div1'); list1 = document.getElementById('list1'); if (list1.selectedIndex==0 || list1.selectedIndex==2 || list1.selectedIndex==5) div1.style.display = 'block'; else div1.style.display = 'none'; } </script> <form name=form1 method=get action=''> <select name=list1 id=list1 onchange="list1change()"> <option value="item1">item1</option> <option value="item2">item2</option> <option value="item3">item3</option> <option value="item4">item4</option> <option value="item5">item5</option> <option value="item6">item6</option> </select> <div name=div1 id=div1 style='display: block;'> <select name=list2> <option value="item1">item1</option> <option value="item2">item2</option> <option value="item3">item3</option> </select> </div> </form> As Karl points out, there is lots of information available on doing this, and general purpose libraries that handle the combination of html, javascript and php to simplify things. Quote Link to comment Share on other sites More sharing options...
c_pattle Posted May 22, 2010 Author Share Posted May 22, 2010 Thanks for your help. I tried to adapt your script to include three divs for three different options but can't seem to get it to work. function list1change() { div1 = document.getElementById('div1'); order_property_details = document.getElementById('order_property_details'); if (order_property_details.selectedIndex==0) div1.style.display = 'block'; else if (order_property_details.selectedIndex==1) div2.style.display = 'block'; else if (order_property_details.selectedIndex==2) div3.style.display = 'block'; else div1.style.display = 'none'; div2.style.display = 'none'; div3.style.display = 'none'; } Quote Link to comment 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.