Question : Javascript... add onmouseover .... variable not working

Hi
I'm trying to attach onmouseover and onmouseout function to all area html tags in the form (reportviewer) and it seems this works however I get the same tooltip text everywhere. In the example below I used i and thought I will get 0 to 15 but all tooltips show value 15 only.

Any ideas how to make the tooltip show the correct value?

Many thanks in advance
Emil
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
function Test() {

            //var doc = window.frames[0][1].document;
            var doc = document.forms['form1'].document;
            var el = doc.getElementsByTagName('AREA');
            var len = el.length;

            for (i = 0; i < len; i++) {
                var ToolTipText = el[i].getAttribute("TITLE");
                el[i].onmouseover = function () { tooltip.show(i); };
                el[i].onmouseout = function () { tooltip.hide() };
            }
        }

Answer : Javascript... add onmouseover .... variable not working

the last value of i is displayed and not the one when you set the function.

try this :

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
function Test() {
		//var doc = window.frames[0][1].document;
		var doc = document.forms['form1'].document;
		var el = doc.getElementsByTagName('AREA');
		var len = el.length;
		
		for (i = 0; i < len; i++) {
			var ToolTipText = el[i].getAttribute("TITLE");
			el[i].onmouseover = function () { tooltip.show(this.value); };
			el[i].onmouseout = function () { tooltip.hide() };
			el[i].setAttribute("value", i);
		}
	}
Random Solutions  
 
programming4us programming4us