Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. onMouseOver handler does not get the argument

onMouseOver handler does not get the argument

Scheduled Pinned Locked Moved .NET (Core and Framework)
questioncsharpjavascript
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hezi
    wrote on last edited by
    #1

    I have a matrix of checkboxes and I would like to get the id on which the mouse is over. I set the onMouseOver handler programmatically by the following C# code in the Page_Load procedure: checkBoxObject.Atributes.Add("onMouseOver","mouseOverHandler(this)"); The client's MouseOverHandler function (JavaScript) is: Function mouseOverHandler(this) { alert(document.getElementById(me.id)) } When I move the mouse over a checkbox I get an empty alert box. It seems that the function "mouseOverHandler " does not get the firing checkbox in the argument"me". The same code works correctly when I change the triggering event from "onMouseOver" to "onClick". 1. Why does it work with "onClick" and dose not work with "onMouseOver" 2. How can I make it to work with "onMouseOver" Thank you Hezi

    K T 2 Replies Last reply
    0
    • H hezi

      I have a matrix of checkboxes and I would like to get the id on which the mouse is over. I set the onMouseOver handler programmatically by the following C# code in the Page_Load procedure: checkBoxObject.Atributes.Add("onMouseOver","mouseOverHandler(this)"); The client's MouseOverHandler function (JavaScript) is: Function mouseOverHandler(this) { alert(document.getElementById(me.id)) } When I move the mouse over a checkbox I get an empty alert box. It seems that the function "mouseOverHandler " does not get the firing checkbox in the argument"me". The same code works correctly when I change the triggering event from "onMouseOver" to "onClick". 1. Why does it work with "onClick" and dose not work with "onMouseOver" 2. How can I make it to work with "onMouseOver" Thank you Hezi

      K Offline
      K Offline
      kadaoui el mehdi
      wrote on last edited by
      #2

      I've tested it and it works.

      function mouseOverHandler(element)
      {
      alert(element.id);
      }

      protected void Page_Load(object sender, EventArgs e)
      {
      CheckBox1.Attributes.Add("onMouseOver", "mouseOverHandler(" + CheckBox1.ClientID + ");");
      }

      1 Reply Last reply
      0
      • H hezi

        I have a matrix of checkboxes and I would like to get the id on which the mouse is over. I set the onMouseOver handler programmatically by the following C# code in the Page_Load procedure: checkBoxObject.Atributes.Add("onMouseOver","mouseOverHandler(this)"); The client's MouseOverHandler function (JavaScript) is: Function mouseOverHandler(this) { alert(document.getElementById(me.id)) } When I move the mouse over a checkbox I get an empty alert box. It seems that the function "mouseOverHandler " does not get the firing checkbox in the argument"me". The same code works correctly when I change the triggering event from "onMouseOver" to "onClick". 1. Why does it work with "onClick" and dose not work with "onMouseOver" 2. How can I make it to work with "onMouseOver" Thank you Hezi

        T Offline
        T Offline
        The Man from U N C L E
        wrote on last edited by
        #3

        You have a Bug/Typo.

        hezi wrote:

        Function mouseOverHandler(this) { alert(document.getElementById(me.id)) }

        The function should read:

        alert(document.getElementById(this.id));

        The 'me' keyword is from VBScript. However, as the other poster showed in his example, it would be better to use a different word for the parameter as the word 'this' has special meaning in JavaScript. Alternately, don't pass the parameter, and just use the 'this' keyword. It will be the object which fired the event. e.g.

        Function mouseOverHandler()
        {
        alert(document.getElementById(this.id))
        }

        If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups