Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy checkboxes and cells. PLEASE HELP!

    I've got a problem, and I'm sure you could help me. I've got an attached file and everything is properly explained there. Please download it an check it. I would be very thankfull.
    It's got to do with checkboxes and cells properties.

    HERE IS THE CODE:

    <html>
    <head>
    <title>THE PROBLEM !</title>

    <script language="javascript" type="text/javascript">
    <!--

    // I THINK THERE SHOULD BE 2 VARIABLES, ONE FOR "CHECKBOX_" AND ANOTHER ONE FOR "TD_"
    // BUT DON'T KNOW TOO MUCH ABOUT JAVASCRIPT...

    function swapBG() {
    if (document.form.checkbox_7.checked) {
    document.getElementById("td_7").style.background='white';
    } else {
    document.getElementById("td_7").style.background='lightblue';
    }
    }
    //-->
    </script>

    </head>
    <body bgcolor="lightblue" onLoad="javascript:swapBG();">

    <p>When the checkbox is checked, the background of the cell should be white, and when it is not checked, the background of the cell should be lightblue (like in the first cell). The problem is that I cannot give different names or identifiers to the CHECKBOXES an to the TDs because I don't know how many cells will be shown in the page (depending of the results given by a query). PHP will give a unique name or identifier to each CHECKBOX and TD, but I don't know how JavaScript could digest all this without previously knowing all the names and identifiers.</p>
    <table width="100%" border="1" cellpadding="5" cellspacing="5">
    <form name="form">
    <tr>

    <!-- THE NUMBERS ("1" "2" "53" "748"...) IN "TD_" AND "CHECKBOX_", WILL BE GIVEN
    // BY PHP ACCORDING TO THE IDENTIFIER FOUND IN THE DATABASE AND WILL BE THE SAME NUMBER
    // IN THE FOLLOWING 2 CASES //-->

    <td id="td_7">
    <div align="left">
    <input type="checkbox" name="checkbox_7" checked onClick="javascript:swapBG();">
    <b>CELL 1 (ok)</b>
    </div>
    </tr>
    <tr>

    <!-- AGAIN, THE NUMBERS ("1" "2" "53" "748"...) IN "TD_" AND "CHECKBOX_", WILL BE GIVEN
    // BY PHP ACCORDING TO THE IDENTIFIER FOUND IN THE DATABASE AND WILL BE THE SAME NUMBER
    // IN THE FOLLOWING 2 CASES //-->

    <td id="td_284">
    <div align="left">
    <input type="checkbox" name="checkbox_284" checked onClick="javascript:swapBG()">
    <b>CELL 2 (ouch!)</b>
    </div>
    </td>
    </tr>

    <!-- AGAIN, THE NUMBERS ("1" "2" "53" "748"...) IN "TD_" AND "CHECKBOX_", WILL BE GIVEN
    // BY PHP ACCORDING TO THE IDENTIFIER FOUND IN THE DATABASE AND WILL BE THE SAME NUMBER
    // IN THE FOLLOWING 2 CASES //-->

    <tr>
    <td id="td_36">
    <div align="left">
    <input type="checkbox" name="checkbox_36" checked onClick="javascript:swapBG()">
    <b>CELL 2 (ouch!)</b>
    </div>
    </td>
    </tr>
    </form>
    </table>
    <p>Thanks in advanced</p>
    </body>
    </html>
    Attached Files Attached Files

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <html>
    <head>
    <title>THE PROBLEM !</title>

    <script language="javascript" type="text/javascript">
    <!--

    function swapBG(oCheckbox) {
    var td = oCheckbox.parentNode.parentNode, bWhich = oCheckbox.checked;
    td.style.background = (bWhich) ? 'white' : 'lightblue';
    }

    //-->
    </script>
    </head>
    <body bgcolor="lightblue">
    <table width="100%" border="1" cellpadding="5" cellspacing="5">
    <form name="form">
    <tr>
    <td id="td_7" bgcolor="white">
    <div align="left">
    <input type="checkbox" name="checkbox_7" checked onclick="swapBG(this)">
    <b>CELL 1 (ok)</b>
    </div>
    </tr>
    <tr>
    <td id="td_284" bgcolor="white">
    <div align="left">
    <input type="checkbox" name="checkbox_284" checked onclick="swapBG(this)">
    <b>CELL 2 (ouch!)</b>
    </div>
    </td>
    </tr>
    <tr>
    <td id="td_36" bgcolor="white">
    <div align="left">
    <input type="checkbox" name="checkbox_36" checked onclick="swapBG(this)">
    <b>CELL 2 (ouch!)</b>
    </div>
    </td>
    </tr>
    </form>
    </table>
    <p>Thanks in advanced</p>
    </body>
    </html>

    http://www.brainjar.com/dhtml/intro/
    Last edited by cheesebagpipe; 06-11-2003 at 10:37 PM.

  • #3
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile thankyou

    Thanks, thanks, thanks !!!! and thanks again for the link.


  •  

    Posting Permissions

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