views:

65

answers:

2

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

+10  A: 

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.

Pointy
A: 
<!doctype html>
<html lang="en">
<head>
<meta charset= "utf-8">    
<title>Added attributes</title>
<script type="text/javascript">

function show_alert(evt){
    evt= window.event || evt;
    var eSrc= evt.srcElement || evt.target; 
    if(eSrc.getAttribute('data-tableisloaded')== "showAlert"){
        alert("alert box: " + eSrc.name + "|" + eSrc.type);
    }
}
onload=function(){
    document.getElementsByName('clickme')[0].onclick=show_alert;
}

</script>
</head>
<body>

<input type="button" name="clickme" data-tableisloaded="showAlert" 
value="Show alert box" >

</body>
</html>

// pointy answered while I was still typing, and I gave him an upvote- but this is what he said....

kennebec