www.webdeveloper.com
Results 1 to 2 of 2

Thread: when a checkbox is checked show a div

  1. #1
    Join Date
    Aug 2014
    Posts
    1

    when a checkbox is checked show a div

    Hello

    I'm trying to show some div's by using some checkboxes

    I have found a good code but it is HTML

    The checkboxes must be in a php code because it depends on an other value if they are shown yes or not

    Her is te HTML code:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8" />
    <title>Checkboxes shown </title>



    </head>
    <script>
    function showMe (it, box) {
    var vis = (box.checked) ? "visible" : "hidden";
    document.getElementById(it).style.visibility = vis;
    }
    </script>
    <form>
    <input type="checkbox" name="c1" onclick="showMe('div1', this)" checked>Show Hide Checkbox for div 1
    <br>
    <input type="checkbox" name="c1" onclick="showMe('div2', this)" checked>Show Hide Checkbox for div 2
    </form><div id="div1">
    <h3 align="center"> this is the first div </h3>
    <table border=1 id="t1">
    <tr>
    <td>i am here!</td>
    </tr>
    </table>
    </div><div id="div2">
    <h3 align="center"> This is the second div </h3>
    <table border=1 id="t1">
    <tr>
    <td>i am here for the second one!</td>
    </tr>
    </table>
    </div>

    </html>

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    727
    Regardless of the "other" codes, you need to write some JS to react to the checkbox click (onclick event). With that you can check any other field you want to check and then show your div.
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL | E_NOTICE);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles