Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript works in IE, but not Firefox

Same old same old, my javascript runs fine in IE but not with Firefox. I've followed all the forms, checked all the forums and responses, and what I've got coded up should work but it's not. Firebug shows the value as "undefined."

Here's what I've got; it's scaled down from a much bigger application, but it shows the same problem:

<html>
<head>
<script type="text/javascript">
function show_alert(evt)
{
if( !evt )
    evt = window.event;

var eSrc;
if( evt.srcElement )
    eSrc = evt.srcElement;
else
    eSrc = evt.target;

if( eSrc.tableisloaded == "showAlert" ) 
    alert("alert box: " + eSrc.name + "|" + eSrc.type);
}

</script>
</head>
<body>

<input type="button" name="clickme" tableisloaded="showAlert"
 onclick="show_alert(event);" value="Show alert box" />

 </body>
</html>

When I run this in IE, I get the alert, which means it is finding the "tableisloaded" argument. Firebug doesn't show it all.

So what am I doing wrong, and is there a way to access the argument? Will I need to change it to a parameter (onclick="show_alert(event,"showAlert");)? I am hoping NOT as it will require a major rewrite of a LOT of code.

Thanks

like image 758
kberson Avatar asked Dec 22 '22 02:12

kberson


1 Answers

Try eSrc.getAttribute("tableisloaded")

Also, if you want to be hip and trendy, you might consider making your pages HTML5 and calling your extra attribute "data-tableIsloaded". That way it'll validate.

like image 121
Pointy Avatar answered Jan 09 '23 00:01

Pointy