Results 1 to 4 of 4

Thread: Bug or simple solution?? Driving me crazy...

  1. #1
    Join Date
    Jun 2007
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Bug or simple solution?? Driving me crazy...

    Have a small anomaly which is driving me crazy.

    The page is pretty much self-explaining...simply load in a browser or check: http://www.drlindmark.se/kevin/script.html

    Code:
    
    <head>
    <style type="text/css" media="screen,print">
    .checked {background-color: #F1F1F1;}
    
    </style>
    <script type="text/javascript">
    function pl(name)
    {
    if (name.checked == true) {name.parentNode.parentNode.className = "checked";} else {name.parentNode.parentNode.className = "xxx";}
    }
    
    function plt(name)
    {
    if (name.checked == true) {name.parentNode.parentNode.parentNode.className = "checked";} else {name.parentNode.parentNode.parentNode.className = "xxx";}
    }
    </script>
    
    
    </head>
    
    <body>
    <form name="form1" method="post" action="">
    <table border="1" cellspacing="0" cellpadding="0" class="">
      <tr>
        <td width="355">Tableclass 1 - not checked and no class. Works fine.</td>
        <td width="120">&nbsp;</td>
        <td width="120">&nbsp;</td>
        <td width="25">
          <input type="checkbox" name="checkbox" id="checkbox" onclick="plt(this)">    </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
    <br>
    <table border="1" cellspacing="0" cellpadding="0" class="checked">
      <tr>
        <td width="355">Tableclass 2 - checked and class set.</td>
        <td width="120">&nbsp;</td>
        <td width="120">&nbsp;</td>
        <td width="25">
          <input name="checkbox" type="checkbox" id="checkbox" onclick="plt(this)" checked>    </td>
      </tr>
      <tr>
        <td><strong>PROBLEM!</strong> Why does not the background change??</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
    <br>
    <table border="1" cellspacing="0" cellpadding="0">
      <tr class="">
        <td width="355">Rowclass 1 - not checked and no class. Works fine.</td>
        <td width="120">&nbsp;</td>
        <td width="120">&nbsp;</td>
        <td width="25">
          <input type="checkbox" name="checkbox2" id="checkbox2" onclick="pl(this)">    </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
    <br>
    <table border="1" cellspacing="0" cellpadding="0">
      <tr class="checked">
        <td width="355">Row class 2 - checked and class set. Works fine.</td>
        <td width="120">&nbsp;</td>
        <td width="120">&nbsp;</td>
        <td width="25">
          <input name="checkbox2" type="checkbox" id="checkbox2" onclick="pl(this)" checked>    </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
    <br>
    </form>
    
    </body>
    </html>

  2. #2
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,920
    Thanks
    2
    Thanked 267 Times in 262 Posts

    Default

    Hi there lindm,

    in your script...
    Code:
    name.parentNode.parentNode.parentNode.className
    ...refers to the tbody element not the table element.
    The solution to your problem is to either change the script to...
    Code:
    name.parentNode.parentNode.parentNode.parentNode.className
    ...or the html to...
    Code:
    
    <table border="1" cellspacing="0" cellpadding="0">
    <tbody class="checked">
    <tr>
    <td width="355">Tableclass 2 - checked and class set.</td>
    <td width="120">&nbsp;</td>
    <td width="120">&nbsp;</td>
    <td width="25">
    <input name="checkbox" type="checkbox" id="checkbox" onclick="plt(this)" checked></td>
    </tr><tr>
    <td><strong>PROBLEM!</strong> Why does not the background change??</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </tbody>
    </table>
    
    coothead

  3. #3
    Join Date
    Jun 2007
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Wonderful!

    Many thanks

  4. #4
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,920
    Thanks
    2
    Thanked 267 Times in 262 Posts

    Default

    No problem, you're welcome.

Bookmarks

Posting Permissions

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