Jump to content

Show & Hide


AnotherQuestion

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/174384-show-hide/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/174384-show-hide/#findComment-919425
Share on other sites

  • 3 weeks later...

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?

Link to comment
https://forums.phpfreaks.com/topic/174384-show-hide/#findComment-929771
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.