PHPBob Posted July 26, 2011 Share Posted July 26, 2011 Hi! Can anyone tell me how to display certain HTML elements based on what someone checks off in a check box? Is there any way to do that dynamically, or must you click Submit and get it on another page? Either way works for me, but preferably the first. Quote Link to comment Share on other sites More sharing options...
WebStyles Posted July 26, 2011 Share Posted July 26, 2011 if you want to alter page options dinamically according to what the user selects, without refreshing the page, you need javascript (theres another forum that can certainly help you with that) you basically capture the users selections with onchange="" and call javascript functions that can in place add forms, images, etc to divs on your page. Quote Link to comment Share on other sites More sharing options...
msaz87 Posted July 26, 2011 Share Posted July 26, 2011 To do it dynamically you'd need to use javascript. If you want to do it with PHP you can do something like this: the form: <form method="post" action="nextPage.php"> <input type="checkbox" name="optionA"> Option A <input type="checkbox" name="optionB"> Option B <input type="checkbox" name="optionC"> Option C </form> the receiving page: <?php $optionA = $_REQUEST['optionA']; $optionB = $_REQUEST['optionB']; $optionC = $_REQUEST['optionC']; if($optionA == "on") { ?> your HTML elements for Option A here <?php } elseif($optionB == "on") { ?> option B <?php } elseif($optionC == "on") { ?> option C <?php } else { ?> if none are selected <?php } ?> The above will change if you need to factor in multiple selections, etc. but that's the basics of it Quote Link to comment Share on other sites More sharing options...
braunshedd Posted July 27, 2011 Share Posted July 27, 2011 If you want to do it all dynamically, AJAX is what you're looking for, however, AJAX is pretty complicated for people who don't understand php and javascript well. Also, AJAX can break back buttons.... 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.