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>

change the function like fu(this)

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

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.

both of you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.