Hightlight a row in a table when....

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jay

    #1

    Hightlight a row in a table when....

    Hi !

    I am writing a page that displays a list of records in a table. Each
    row for each record. Each row has a checkbox associated with it. Does
    anybody know how to highlight a row when I click on a checkbox in that
    row and unhightlight it when I re-click that checkbox? (like in
    "hotmail" and "yahoo" e-mail when u select a message to delete).


    Any help would be appreciated !

    Thank you in advance !

    Jay
  • mscir

    #2
    Re: Hightlight a row in a table when....

    Jay wrote:[color=blue]
    > Hi !
    > I am writing a page that displays a list of records in a table. Each
    > row for each record. Each row has a checkbox associated with it. Does
    > anybody know how to highlight a row when I click on a checkbox in that
    > row and unhightlight it when I re-click that checkbox? (like in
    > "hotmail" and "yahoo" e-mail when u select a message to delete).
    >
    > Any help would be appreciated !
    > Thank you in advance !
    > Jay[/color]

    this works in IE6, Netscape 7.1, Firefox 0.8:

    <script type="text/javascript">
    var color1="#D2E9FF ";
    var color2="#99CCFF ";
    function changebkg(ckbox ,rownum) {
    if (ckbox.checked)
    document.getEle mentById('row'+ rownum).style.b ackground=color 1;
    else
    document.getEle mentById('row'+ rownum).style.b ackground=color 2;
    }
    </script>

    <table width=110 bgcolor="99CCFF " border=1>
    <tr id="row0" name="row0">
    <td width="10"><inp ut type="checkbox" name="C1" value="ON"
    onclick="change bkg(this,0)">&n bsp;</td>
    <td width="50">&nbs p;</td>
    <td width="50">&nbs p;</td>
    </tr>
    <tr>
    <tr id="row1" name="row1">
    <td width="10"><inp ut type="checkbox" name="C1" value="ON"
    onclick="change bkg(this,1)">&n bsp;</td>
    <td width="50">&nbs p;</td>
    <td width="50">&nbs p;</td>
    </tr>
    </table>

    Mike

    Comment

    • Jay

      #3
      Re: Hightlight a row in a table when....

      Thank a lot Mike, It worked !!!!! Jayyyyyy

      Jay

      Comment

      • Martin Honnen

        #4
        Re: Hightlight a row in a table when....



        Jay wrote:
        [color=blue]
        > I am writing a page that displays a list of records in a table. Each
        > row for each record. Each row has a checkbox associated with it. Does
        > anybody know how to highlight a row when I click on a checkbox in that
        > row and unhightlight it when I re-click that checkbox? (like in
        > "hotmail" and "yahoo" e-mail when u select a message to delete).[/color]

        Here is an example that traverses the document tree for a <tr> ancestor
        element and then changes its inline background-color style as needed

        <html lang="en">
        <head>
        <title>changi ng the background-color of a table row</title>
        <script type="text/javascript">
        var backgroundColor = 'lightblue';
        function setRowBackgroun d (childCheckbox) {
        var row = childCheckbox.p arentNode;
        while (row && row.tagName.toL owerCase() != 'tr') {
        row = row.parentNode;
        }
        if (row && row.style) {
        if (childCheckbox. checked) {
        row.style.backg roundColor = backgroundColor ;
        }
        else {
        row.style.backg roundColor = '';
        }
        }
        }
        </script>
        <style type="text/css">
        tr {
        background-color: lightgreen;
        }
        </style>
        </head>
        <body>
        <table>
        <tbody>
        <tr>
        <td>
        <label>
        delete
        <input type="checkbox" name="message" value="1"
        onclick="setRow Background(this );">
        </label>
        <td>
        All for Kibology
        </td>
        </tr>

        <tr>
        <td>
        <label>
        delete
        <input type="checkbox" name="message" value="2"
        onclick="setRow Background(this );">
        </label>
        <td>
        Kibology for all
        </td>
        </tr>
        </tbody>
        </table>
        </body>
        </html>

        --

        Martin Honnen
        http://JavaScript.FAQTs.com/

        Comment

        Working...