illuz1on Posted July 4, 2008 Share Posted July 4, 2008 [code]Hi, I have a select like below in my form, I want a second box to populate but differently for each activity. I would like to do this by means of something like this (case method really).. Any help would be much appreciated.. been struggling with it. Thanks alot, Chris [code] If () case '1'; query to fill for activity 1 case '2'; query to fill for activity 2 etc.. etc.. This is my current select for activity... <select name="posActivity" id="posActivity"> <option selected>Select an option</option> <option value="Abseiling Table Mountain">Abseiling Table Mountain</option> <option value="Breede River Rafting">Breede River Rafting</option> <option value="Table Mountain Hiking">Table Mountain Hiking</option> <option value="Kloofing Suicide Gorge">Kloofing Suicide Gorge</option> <option value="Surfing Cape Peninsula Tour">Surfing Cape Peninsula Tour</option> <option value="Quad Biking Mountain Expedition">Quad Biking Mountain Expedition</option> <option value="Scuba Diving">Scuba Diving</option> <option value="Shark Cage Diving">Shark Cage Diving</option> <option value="Tandem Skydiving">Tandem Skydiving</option> <option value="Sunset Horse Riding">Sunset Horse Riding</option> <option value="Cape Peninsula Tour">Cape Peninsula Tour</option> <option value="Safari">Safari</option> <option value="Wine Tasting">Wine Tasting</option> </select> [/code][/code] Quote Link to comment https://forums.phpfreaks.com/topic/113194-populate-drop-box-with-case-statements/ Share on other sites More sharing options...
Boo-urns Posted July 4, 2008 Share Posted July 4, 2008 You'll need to use javascript to do what you are wanting. If you are using jQuery it would be <script type="text/javascript" language="javascript"> $('#posActivity').change(function(){ var selectedOption = $(this).val(); switch(selectedOption) { case "Abseiling Table Mountain": $('#secondBox').load('includes/abseilingMountain.php'); break; } }); </script> Or if the second box is a dropdown you could do a show on it. I'm also sure there is a way with plain javascript except I don't know off the top of my head hopefully this helps ya out. Quote Link to comment https://forums.phpfreaks.com/topic/113194-populate-drop-box-with-case-statements/#findComment-581601 Share on other sites More sharing options...
illuz1on Posted July 4, 2008 Author Share Posted July 4, 2008 Thanks for the reply, still a bit confused though.. "Or if the second box is a dropdown you could do a show on it. I'm also sure there is a way with plain javascript except I don't know off the top of my head hopefully this helps ya out." The second one would be a dropdown - what do you mean a show on it? What would the include file contents be? Quote Link to comment https://forums.phpfreaks.com/topic/113194-populate-drop-box-with-case-statements/#findComment-581633 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.