row and column...

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

    #1

    row and column...

    Dear All,

    I have this,

    <table>
    <colgroup>
    <col id="column1" />
    <col id="column2" />
    <col id="column3" />
    </colgroup>
    <tr onmouseover="do hi-light" onmouseout="und o hi-light">
    <td></td>
    <td></td>
    <td></td>
    </tr>
    </table>

    I can do the hi-light on the first two columns except the last when mouse
    moveover the row, but now I want to not hi-lighting the row when the last
    column is being over, coz I have three separate links on the last column
    cell. Is it possible knowing which column is being selected when a row is
    selected? I do not want to set any attribute inside <td>
    Can I check it inside the onmouseover/out function?

    Regards,
    Wandy


  • Randy Webb

    #2
    Re: row and column...

    Wandy Tang wrote:[color=blue]
    > Dear All,
    >
    > I have this,
    >
    > <table>
    > <colgroup>
    > <col id="column1" />
    > <col id="column2" />
    > <col id="column3" />
    > </colgroup>
    > <tr onmouseover="do hi-light" onmouseout="und o hi-light">
    > <td></td>
    > <td></td>
    > <td></td>
    > </tr>
    > </table>
    >
    > I can do the hi-light on the first two columns except the last when mouse
    > moveover the row, but now I want to not hi-lighting the row when the last
    > column is being over, coz I have three separate links on the last column
    > cell. Is it possible knowing which column is being selected when a row is
    > selected? I do not want to set any attribute inside <td>[/color]

    Why? Trying to determine from the tr which td is mousedover is
    tremedously more difficult than modifying the td tags.
    [color=blue]
    > Can I check it inside the onmouseover/out function?[/color]

    The fact that the onmouseover and onmouseout fire at all is odd.
    Function names can not contain spaces, and it should include the () part
    of the function call. Let me guess, you are testing in IE?



    --
    Randy
    comp.lang.javas cript FAQ - http://jibbering.com/faq

    Comment

    • Martin Honnen

      #3
      Re: row and column...



      Wandy Tang wrote:

      [color=blue]
      > I have this,
      >
      > <table>
      > <colgroup>
      > <col id="column1" />
      > <col id="column2" />
      > <col id="column3" />
      > </colgroup>
      > <tr onmouseover="do hi-light" onmouseout="und o hi-light">
      > <td></td>
      > <td></td>
      > <td></td>
      > </tr>
      > </table>
      >
      > I can do the hi-light on the first two columns except the last when mouse
      > moveover the row, but now I want to not hi-lighting the row when the last
      > column is being over, coz I have three separate links on the last column
      > cell. Is it possible knowing which column is being selected when a row is
      > selected? I do not want to set any attribute inside <td>
      > Can I check it inside the onmouseover/out function?[/color]

      I am not sure I have understood what you want but here is an example
      checking the cellIndex property of a <td> element:

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd">
      <html lang="en">
      <head>
      <title>cellInde x</title>
      <script type="text/javascript">
      function highlight (row, evt, backgroundColor ) {
      var sourceElement;
      if (evt.srcElement ) {
      sourceElement = evt.srcElement;
      }
      else if (evt.target) {
      sourceElement = evt.target;
      if (sourceElement. nodeType != 1) {
      sourceElement = sourceElement.p arentNode;
      }
      }
      if (sourceElement == row && row.style) {
      row.style.backg roundColor = backgroundColor ;
      }
      else {
      var targetCell = sourceElement;
      while (targetCell && targetCell.tagN ame.toLowerCase () != 'td') {
      targetCell = targetCell.pare ntNode;
      }
      if (targetCell && targetCell.cell Index != 2) {
      row.style.backg roundColor = backgroundColor ;
      }
      }
      }
      </script>
      </head>
      <body>
      <table border="1">
      <tbody>
      <tr onmouseover="hi ghlight(this, event, 'lightblue');"
      onmouseout="hig hlight(this, event, '')">
      <td>
      0, 0
      </td>
      <td>
      0, 1
      </td>
      <td>
      0, 2
      <a href="http://JavaScript.FAQT S.com/">JavaScript.FA QTs.com</a>
      </td>
      </tr>
      </tbody>
      </table>
      </body>
      </html>

      That way the whole row (<tr>) changes the backgroundColor but only if
      you move the mouse over the first or second cell.


      --

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

      Comment

      • Evertjan.

        #4
        Re: row and column...

        Martin Honnen wrote on 05 sep 2004 in comp.lang.javas cript:[color=blue]
        > Wandy Tang wrote:[color=green]
        >> I can do the hi-light on the first two columns except the last when
        >> mouse moveover the row, but now I want to not hi-lighting the row
        >> when the last column is being over, coz I have three separate links
        >> on the last column cell. Is it possible knowing which column is being
        >> selected when a row is selected? I do not want to set any attribute
        >> inside <td> Can I check it inside the onmouseover/out function?[/color]
        >
        > I am not sure I have understood what you want but here is an example
        > checking the cellIndex property of a <td> element:
        >
        > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        > "http://www.w3.org/TR/html4/strict.dtd">
        > <html lang="en">
        > <head>
        > <title>cellInde x</title>
        > <script type="text/javascript">
        > function highlight (row, evt, backgroundColor ) {
        > var sourceElement;
        > if (evt.srcElement ) {
        > sourceElement = evt.srcElement;
        > }
        > else if (evt.target) {
        > sourceElement = evt.target;
        > if (sourceElement. nodeType != 1) {
        > sourceElement = sourceElement.p arentNode;
        > }
        > }
        > if (sourceElement == row && row.style) {
        > row.style.backg roundColor = backgroundColor ;
        > }
        > else {
        > var targetCell = sourceElement;
        > while (targetCell && targetCell.tagN ame.toLowerCase () != 'td') {
        > targetCell = targetCell.pare ntNode;
        > }
        > if (targetCell && targetCell.cell Index != 2) {
        > row.style.backg roundColor = backgroundColor ;
        > }
        > }
        >}
        > </script>
        > </head>
        > <body>
        > <table border="1">
        > <tbody>
        > <tr onmouseover="hi ghlight(this, event, 'lightblue');"
        > onmouseout="hig hlight(this, event, '')">
        > <td>
        > 0, 0
        > </td>
        > <td>
        > 0, 1
        > </td>
        > <td>
        > 0, 2
        > <a href="http://JavaScript.FAQT S.com/">JavaScript.FA QTs.com</a>
        > </td>
        > </tr>
        > </tbody>
        > </table>
        > </body>
        > </html>
        >[/color]

        Nice
        [color=blue]
        > That way the whole row (<tr>) changes the backgroundColor but only if
        > you move the mouse over the first or second cell.[/color]

        change both occurances of

        row.style.backg roundColor = backgroundColor ;

        to

        row.firstChild. style.backgroun dColor = backgroundColor ;
        row.firstChild. nextSibling.sty le.backgroundCo lor = backgroundColor ;



        --
        Evertjan.
        The Netherlands.
        (Please change the x'es to dots in my emailaddress,
        but let us keep the discussions in the newsgroup)

        Comment

        • Michael Winter

          #5
          Re: row and column...

          On Sun, 05 Sep 2004 02:00:32 -0400, Randy Webb <HikksNotAtHome @aol.com>
          wrote:
          [color=blue]
          > Wandy Tang wrote:[/color]

          [snip]
          [color=blue][color=green]
          >> <tr onmouseover="do hi-light" onmouseout="und o hi-light">[/color][/color]

          [snip]
          [color=blue]
          > The fact that the onmouseover and onmouseout fire at all is odd.
          > Function names can not contain spaces, and it should include the () part
          > of the function call. Let me guess, you are testing in IE?[/color]

          I think you'll find it's just a simplification. :)

          Mike

          --
          Michael Winter
          Replace ".invalid" with ".uk" to reply by e-mail.

          Comment

          • Martin Honnen

            #6
            Re: row and column...



            Evertjan. wrote:
            [color=blue]
            > Martin Honnen wrote on 05 sep 2004 in comp.lang.javas cript:[/color]
            [color=blue][color=green]
            >><script type="text/javascript">
            >>function highlight (row, evt, backgroundColor ) {
            >> var sourceElement;
            >> if (evt.srcElement ) {
            >> sourceElement = evt.srcElement;
            >> }
            >> else if (evt.target) {
            >> sourceElement = evt.target;
            >> if (sourceElement. nodeType != 1) {
            >> sourceElement = sourceElement.p arentNode;
            >> }
            >> }
            >> if (sourceElement == row && row.style) {
            >> row.style.backg roundColor = backgroundColor ;
            >> }
            >> else {
            >> var targetCell = sourceElement;
            >> while (targetCell && targetCell.tagN ame.toLowerCase () != 'td') {
            >> targetCell = targetCell.pare ntNode;
            >> }
            >> if (targetCell && targetCell.cell Index != 2) {
            >> row.style.backg roundColor = backgroundColor ;
            >> }
            >> }
            >>}
            >></script>[/color][/color]

            [color=blue][color=green]
            >><table border="1">
            >><tbody>
            >><tr onmouseover="hi ghlight(this, event, 'lightblue');"
            >> onmouseout="hig hlight(this, event, '')">
            >><td>
            >>0, 0
            >></td>
            >><td>
            >>0, 1
            >></td>
            >><td>
            >>0, 2
            >><a href="http://JavaScript.FAQT S.com/">JavaScript.FA QTs.com</a>
            >></td>
            >></tr>
            >></tbody>
            >></table>
            >></body>
            >></html>
            >>[/color][/color]

            [color=blue]
            > change both occurances of
            >
            > row.style.backg roundColor = backgroundColor ;
            >
            > to
            >
            > row.firstChild. style.backgroun dColor = backgroundColor ;
            > row.firstChild. nextSibling.sty le.backgroundCo lor = backgroundColor ;[/color]

            Have you tried that with Mozilla or Netscape? The firstChild is a text
            node so trying to change its style results in an error.

            --

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

            Comment

            • Evertjan.

              #7
              Re: row and column...

              Martin Honnen wrote on 05 sep 2004 in comp.lang.javas cript:[color=blue][color=green]
              >> change both occurances of
              >>
              >> row.style.backg roundColor = backgroundColor ;
              >>
              >> to
              >>
              >> row.firstChild. style.backgroun dColor = backgroundColor ;
              >> row.firstChild. nextSibling.sty le.backgroundCo lor = backgroundColor ;[/color]
              >
              > Have you tried that with Mozilla or Netscape? The firstChild is a text
              > node so trying to change its style results in an error.[/color]

              No, why so negative, do you have a better solution?

              Please explain the meaning of "textnode" here.


              --
              Evertjan.
              The Netherlands.
              (Please change the x'es to dots in my emailaddress,
              but let us keep the discussions in the newsgroup)

              Comment

              • Michael Winter

                #8
                Re: row and column...

                On 05 Sep 2004 15:56:18 GMT, Evertjan. <exjxw.hannivoo rt@interxnl.net >
                wrote:

                [snip]
                [color=blue]
                > Please explain the meaning of "textnode" here.[/color]

                In the document tree, virtually *everything* is represented by some form
                of node. It isn't just elements - comments, text, the DTD - they are all
                nodes.

                A text node is a node in the tree that represents the text you'll find as
                the content of an element, such as a paragraph.

                If you want some more information, read the DOM Core Specification. It
                covers the structure of the document tree.

                <URL:http://www.w3.org/TR/DOM-Level-2-Core>

                Hope that helps,
                Mike

                --
                Michael Winter
                Replace ".invalid" with ".uk" to reply by e-mail.

                Comment

                • Martin Honnen

                  #9
                  Re: row and column...



                  Evertjan. wrote:
                  [color=blue]
                  > Martin Honnen wrote on 05 sep 2004 in comp.lang.javas cript:
                  >[color=green][color=darkred]
                  >>>change both occurances of
                  >>>
                  >>> row.style.backg roundColor = backgroundColor ;
                  >>>
                  >>>to
                  >>>
                  >>> row.firstChild. style.backgroun dColor = backgroundColor ;
                  >>> row.firstChild. nextSibling.sty le.backgroundCo lor = backgroundColor ;[/color]
                  >>
                  >>Have you tried that with Mozilla or Netscape? The firstChild is a text
                  >>node so trying to change its style results in an error.[/color]
                  >
                  >
                  > No, do you have a better solution?[/color]

                  I posted a working solution as far as I thought I was able to understand
                  the original question, you followed that up with some changes that would
                  cause a script error in Netscape/Mozilla.
                  [color=blue]
                  > Please explain the meaning of "textnode" here.[/color]

                  A text node as defined in the W3C DOM Core, it is a node with nodeType
                  being 3.

                  --

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

                  Comment

                  • Evertjan.

                    #10
                    Re: row and column...

                    Martin Honnen wrote on 05 sep 2004 in comp.lang.javas cript:[color=blue][color=green]
                    >> No, do you have a better solution?[/color]
                    >
                    > I posted a working solution as far as I thought I was able to understand
                    > the original question, you followed that up with some changes that would
                    > cause a script error in Netscape/Mozilla.[/color]

                    As far as I understood, the OP wanted only the two first TD's highlighted,
                    as per my IE code, so if yiou know a cross broweser solution, ...



                    --
                    Evertjan.
                    The Netherlands.
                    (Please change the x'es to dots in my emailaddress,
                    but let us keep the discussions in the newsgroup)

                    Comment

                    • Martin Honnen

                      #11
                      Re: row and column...



                      Evertjan. wrote:

                      [color=blue]
                      > As far as I understood, the OP wanted only the two first TD's highlighted,
                      > as per my IE code, so if yiou know a cross broweser solution, ...[/color]

                      The row element object has a cells property you could loop through and
                      change the style of the cells you want to change.

                      --

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

                      Comment

                      • Evertjan.

                        #12
                        Re: row and column...

                        Martin Honnen wrote on 06 sep 2004 in comp.lang.javas cript:[color=blue]
                        > Evertjan. wrote:
                        >[color=green]
                        >> As far as I understood, the OP wanted only the two first TD's
                        >> highlighted, as per my IE code, so if yiou know a cross broweser
                        >> solution, ...[/color]
                        >
                        > The row element object has a cells property you could loop through and
                        > change the style of the cells you want to change.[/color]

                        Could you enlighten us/the OP with some code, please.



                        --
                        Evertjan.
                        The Netherlands.
                        (Please change the x'es to dots in my emailaddress,
                        but let us keep the discussions in the newsgroup)

                        Comment

                        • Martin Honnen

                          #13
                          Re: row and column...



                          Evertjan. wrote:
                          [color=blue]
                          > Martin Honnen wrote on 06 sep 2004 in comp.lang.javas cript:[/color]
                          [color=blue][color=green]
                          >>The row element object has a cells property you could loop through and
                          >>change the style of the cells you want to change.[/color]
                          >
                          > Could you enlighten us/the OP with some code, please.[/color]

                          Like this:

                          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
                          "http://www.w3.org/TR/html4/strict.dtd">
                          <html lang="en">
                          <head>
                          <title>cellInde x</title>
                          <script type="text/javascript">
                          function highlightCells (row, cellIndexToExcl ude, backgroundColor ) {
                          for (var c = 0; c < row.cells.lengt h; c++) {
                          if (c != cellIndexToExcl ude) {
                          row.cells[c].style.backgrou ndColor = backgroundColor ;
                          }
                          }
                          }

                          function highlight (row, cellIndexToExcl ude, evt, backgroundColor ) {
                          var sourceElement;
                          if (evt.srcElement ) {
                          sourceElement = evt.srcElement;
                          }
                          else if (evt.target) {
                          sourceElement = evt.target;
                          if (sourceElement. nodeType != 1) {
                          sourceElement = sourceElement.p arentNode;
                          }
                          }
                          if (sourceElement == row && row.style) {
                          highlightCells( row, cellIndexToExcl ude, backgroundColor );
                          }
                          else {
                          var targetCell = sourceElement;
                          while (targetCell && targetCell.tagN ame.toLowerCase () != 'td') {
                          targetCell = targetCell.pare ntNode;
                          }
                          if (targetCell && targetCell.cell Index != cellIndexToExcl ude) {
                          highlightCells( row, cellIndexToExcl ude, backgroundColor )
                          }
                          }
                          }
                          </script>
                          </head>
                          <body>
                          <table border="1">
                          <tbody>
                          <tr onmouseover="hi ghlight(this, 2, event, 'lightblue');"
                          onmouseout="hig hlight(this, 2, event, '')">
                          <td>
                          0, 0
                          </td>
                          <td>
                          0, 1
                          </td>
                          <td>
                          0, 2
                          <a href="http://JavaScript.FAQT S.com/">JavaScript.FA QTs.com</a>
                          </td>
                          </tr>
                          </tbody>
                          </table>
                          </body>
                          </html>
                          --

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

                          Comment

                          • Evertjan.

                            #14
                            Re: row and column...

                            Martin Honnen wrote on 06 sep 2004 in comp.lang.javas cript:[color=blue]
                            > Like this:[/color]

                            Thank you,

                            Wow, this not something I can remember next time I need it.

                            Then, I will look up this posting in Google groups.

                            --
                            Evertjan.
                            The Netherlands.
                            (Please change the x'es to dots in my emailaddress,
                            but let us keep the discussions in the newsgroup)

                            Comment

                            Working...