AnotherQuestion Posted September 15, 2009 Share Posted September 15, 2009 I cant find out how to do this in php or if it is possible. If not can anyone suggest? When user selects Five check boxes an image shows: Thanks P.s. I would normally post some code but I have no idea in php. In asp.net it would be something like If Chkbox1.Checkbox = True AND....... Then ...do this Quote Link to comment https://forums.phpfreaks.com/topic/174384-show-hide/ Share on other sites More sharing options...
Adam Posted September 16, 2009 Share Posted September 16, 2009 Giving a mixed image of what you're trying to achieve. Do you mean that you want to use *PHP* to display (or not) something on the page? Or do you want to use JavaScript to hide / show something as it's clicked? Quote Link to comment https://forums.phpfreaks.com/topic/174384-show-hide/#findComment-919393 Share on other sites More sharing options...
priti Posted September 16, 2009 Share Posted September 16, 2009 This you can achieve in PHP using AJAX Quote Link to comment https://forums.phpfreaks.com/topic/174384-show-hide/#findComment-919414 Share on other sites More sharing options...
Adam Posted September 16, 2009 Share Posted September 16, 2009 Actually re-read the post a few times makes more sense now, though can't see why you'd think you'd use PHP for this? It's a JavaScript problem (and nothing to do with AJAX, priti). There's probably a variety of ways you could do this, here's a very rough demo of how it could be done: <html> <head> <script type="text/javascript"> function updateChecks() { var check = document.forms[0].elements['checkbox_name']; var check_count = 0; for (i = 0; i < check.length; i++) { if (check[i].checked == true) { check_count++; } } if (check_count >= 5) { document.getElementById('your_image').style.display = 'block'; // or 'inline' depending on element / desired position } else { document.getElementById('your_image').style.display = 'none'; } return true; } </script> </head> <body> <form> <input type="checkbox" name="checkbox_name" value="check1" onclick="updateChecks();" /> check1<br /> <input type="checkbox" name="checkbox_name" value="check2" onclick="updateChecks();" /> check2<br /> <input type="checkbox" name="checkbox_name" value="check3" onclick="updateChecks();" /> check3<br /> <input type="checkbox" name="checkbox_name" value="check4" onclick="updateChecks();" /> check4<br /> <input type="checkbox" name="checkbox_name" value="check5" onclick="updateChecks();" /> check5<br /> </form> <img src="img/my_image.jpg" alt="your Image" id="your_image" style="display: none;" /> </body> </html> Obviously you'll need to adapt this more to your needs but, should be a good starting point. Quote Link to comment https://forums.phpfreaks.com/topic/174384-show-hide/#findComment-919425 Share on other sites More sharing options...
Matthew Herren Posted October 3, 2009 Share Posted October 3, 2009 Ok i was trying something like this in a form. I one check box was checked it would display one block of fields (like a address clock, yah know address state city zip), if the second there would be 2 blocks of fields displayed. would that be done the same way? Quote Link to comment https://forums.phpfreaks.com/topic/174384-show-hide/#findComment-929771 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.