0

I am an absolute beginner with javascript
and have no idea how to solve this one.
got a function fu() which should display the NAME of the image upon onmouseover,but when I try it,all the images show the same name,although they have different names in the code.

I thought the problem might be in the getElementById argument,that is why i've put 3 question marks instead of an ID...

Thx

<HTML>
<HEAD>

<SCRIPT language="JavaScript">
function fu(){
    var m = document.getElementById("???").getAttribute("NAME");
    alert(m);
}
</SCRIPT>
</HEAD>

<BODY>
<IMG id="something" NAME="pic1" SRC="1.jpg" height="50" width="50" 
onmouseover="fu()" >

<IMG id="somethingelse" NAME="pic2" SRC="2.jpg" height="50" width="50" 
onmouseover="fu()">
</BODY>
</HTML>
3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by skurenak
0

change the function like fu(this)

function fu(obj)
var m = document.getElementById(obj.id).getAttribute("NAME");

Edited by peter_budo: Correcting code tags

1

They will show the same name because you can only hard code one element id, what u can do is this:

onmouseover=fu(this)

then in the javascript function change it to this:

function fu(el){
alert(el.name);
}

by sending in the this property u are sending the element object to teh function and thus will be able to retrieve any attribute of that element.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.