onMouseOver handler does not get the argument
-
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
-
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
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 + ");");
} -
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
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]