Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.