Newbee Question

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

    Newbee Question

    Hi, I'm just learning this new scripting language.

    I have created a little script (see below). The HTML builds a table and one
    of the cells has a OnMouseOver parameter which I have set to my "Hello"
    function. How do I reference the cell used to trigger "Hello". For
    example, can I change the background color of the cells as the mouse passes
    over them?

    <TD onMouseOver="he llo()">test</TD>

    Within hello, how do I reference the TD cell that triggered hello?

    I hope this makes sense.

    Thanks in Advance!

    Paul
    Minneapolis






    <html>
    <head>
    <title>CSS - Example 1</title>
    <SCRIPT LANGUAGE="JavaS cript">
    <!-- // Activate cloak
    function hello()
    /*************** *************** *************** *************** *****
    `description`
    11/9/2003 12:37PM
    *************** *************** *************** *************** *****/
    {

    alert("test");
    /* how do I reference the cell that invoked this script" */

    } // hello()
    // Deactivate cloak -->
    </SCRIPT>
    <link rel=stylesheet type="text/css"
    href="css1.css"
    title="Example 1">
    </head>
    <body>
    <h1>Test H1</h1>
    <table align="center" class=test>
    <TR>
    <TD onMouseOver="he llo()">test</TD>
    <TD>test</TD>
    </TR>
    <TR>
    <TD>test</TD>
    <TD>test</TD>
    </TR>
    </table>
    <h1>Test H1</h1>
    </body>
    </html>



  • VK

    #2
    Re: Newbee Question

    <td onMouseOver="do WhatYouWantWith (this)"></td>

    function doWhatYouWantWi th(obj) {
    obj.style.backg roundColor = myColor;
    // and so on
    }


    Comment

    • Matt Eberts

      #3
      Re: Newbee Question


      "Paul Baker" <pbaker01@minds pring.com> wrote in message
      news:bom26n0m2@ enews2.newsguy. com...[color=blue]
      > Hi, I'm just learning this new scripting language.
      >
      > I have created a little script (see below). The HTML builds a table and[/color]
      one[color=blue]
      > of the cells has a OnMouseOver parameter which I have set to my "Hello"
      > function. How do I reference the cell used to trigger "Hello". For
      > example, can I change the background color of the cells as the mouse[/color]
      passes[color=blue]
      > over them?[/color]

      Depending on the browser, event handlers either recieve an event object as a
      parameter (Mozilla, DOM event model compliant browsers), or can access the
      event object on the window object (IE).

      Here's an example

      function hello(event)
      {

      if(typeof event == "undefined" )
      {
      event = window.event;
      }

      //event.target stores the object reference for the node that was the source
      of the event for the DOM event model.
      //event.srcElemen t stores the object reference for the node that was the
      source of the event for IE
      var src = event.target || event.srcElemen t;
      }

      Matt


      Comment

      • Evertjan.

        #4
        Re: Newbee Question

        Paul Baker wrote on 09 nov 2003 in comp.lang.javas cript:
        [color=blue]
        > <TD onMouseOver="he llo()">test</TD>
        >
        > Within hello, how do I reference the TD cell that triggered hello?
        >[/color]

        ....
        <TD id="myidea" onMouseOver="he llo(this)">test </TD>
        ....

        <script>
        function hello(x){
        alert(x.id)
        alert(x.innerTe xt) // IE
        }
        </script>

        --
        Evertjan.
        The Netherlands.
        (Please change the x'es to dots in my emailaddress)

        Comment

        • Paul Baker

          #5
          Re: Newbee Question

          Hi again,

          Yes, I can see how "this" could be used. I can display parameters
          associated with "this" but is it possible to actually change the parameters
          dynamically. Like my example, can I change the background color of the cells
          as the mouse passes over them?

          Thank again!

          Paul




          "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
          news:Xns942ED58 4A8EF1eejj99@19 4.109.133.29...[color=blue]
          > Paul Baker wrote on 09 nov 2003 in comp.lang.javas cript:
          >[color=green]
          > > <TD onMouseOver="he llo()">test</TD>
          > >
          > > Within hello, how do I reference the TD cell that triggered hello?
          > >[/color]
          >
          > ...
          > <TD id="myidea" onMouseOver="he llo(this)">test </TD>
          > ...
          >
          > <script>
          > function hello(x){
          > alert(x.id)
          > alert(x.innerTe xt) // IE
          > }
          > </script>
          >
          > --
          > Evertjan.
          > The Netherlands.
          > (Please change the x'es to dots in my emailaddress)[/color]


          Comment

          • Evertjan.

            #6
            Re: Newbee Question

            Paul Baker wrote on 10 nov 2003 in comp.lang.javas cript:
            [color=blue]
            > Yes, I can see how "this" could be used. I can display parameters
            > associated with "this" but is it possible to actually change the
            > parameters dynamically. Like my example, can I change the background
            > color of the cells as the mouse passes over them?
            >[/color]

            Sure, why don't you try?

            You will have to read up on css, perhaps

            [color=blue]
            > <TD onMouseOver="he llo(this)">test </TD>
            > ...
            >
            > <script>
            > function hello(x){[/color]

            x.style.backgro undColor = "yellow"
            [color=blue]
            > }
            > </script>[/color]


            --
            Evertjan.
            The Netherlands.
            (Please change the x'es to dots in my emailaddress)

            Comment

            • Paul Baker

              #7
              Re: Newbee Question

              Thanks...

              "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
              news:Xns942F5AE BF5E58eejj99@19 4.109.133.29...[color=blue]
              > Paul Baker wrote on 10 nov 2003 in comp.lang.javas cript:
              >[color=green]
              > > Yes, I can see how "this" could be used. I can display parameters
              > > associated with "this" but is it possible to actually change the
              > > parameters dynamically. Like my example, can I change the background
              > > color of the cells as the mouse passes over them?
              > >[/color]
              >
              > Sure, why don't you try?
              >
              > You will have to read up on css, perhaps
              >
              >[color=green]
              > > <TD onMouseOver="he llo(this)">test </TD>
              > > ...
              > >
              > > <script>
              > > function hello(x){[/color]
              >
              > x.style.backgro undColor = "yellow"
              >[color=green]
              > > }
              > > </script>[/color]
              >
              >
              > --
              > Evertjan.
              > The Netherlands.
              > (Please change the x'es to dots in my emailaddress)[/color]


              Comment

              Working...