- Sep 28, 2002
- 226
- 0
- 0
Hi,
Just wondering if I can get some help from you experts on how to solve an HTML / JS problem that I am having. Essentially, I am trying to write a JS function which will return the "name" attribute of the image which calls the function. Here is the the HTML code which I have written for the image (I am using square brackets instead of angled brackets so this post doesn't get messed up...please replace the square brackets with the appropriate angled brackets)
[a name="image1" href="link.htm" onMouseOver="returnMyName(event)"]
[/a]
Here is the JS code for the "returnMyName()" function:
function returnMyName(event) {
var imageName;
var doc = document;
if(doc.getElementById) {
if (navigator.appName == "Microsoft Internet Explorer") {
imageName = window.event.srcElement.name;
}
else if (navigator.appName == "Netscape") {
imageName = event.currentTarget.name;
}
}
if (imageName) {
alert(imageName);
}
}
The above coding works well with IE (it will bring up an alert saying "image1"). However, it does not work with Netscape or Firefox. The problem, obviously is the "event.currentTarget.name" code. I don't believe this is the correct syntax to get the name attribute of the image.
How can I fix this code? I have been searching on the net for more info on event.currentTarget, but I am at a loss.
Thanks for any help.
Just wondering if I can get some help from you experts on how to solve an HTML / JS problem that I am having. Essentially, I am trying to write a JS function which will return the "name" attribute of the image which calls the function. Here is the the HTML code which I have written for the image (I am using square brackets instead of angled brackets so this post doesn't get messed up...please replace the square brackets with the appropriate angled brackets)
[a name="image1" href="link.htm" onMouseOver="returnMyName(event)"]
[/a]
Here is the JS code for the "returnMyName()" function:
function returnMyName(event) {
var imageName;
var doc = document;
if(doc.getElementById) {
if (navigator.appName == "Microsoft Internet Explorer") {
imageName = window.event.srcElement.name;
}
else if (navigator.appName == "Netscape") {
imageName = event.currentTarget.name;
}
}
if (imageName) {
alert(imageName);
}
}
The above coding works well with IE (it will bring up an alert saying "image1"). However, it does not work with Netscape or Firefox. The problem, obviously is the "event.currentTarget.name" code. I don't believe this is the correct syntax to get the name attribute of the image.
How can I fix this code? I have been searching on the net for more info on event.currentTarget, but I am at a loss.
Thanks for any help.