Is there any way I can attach a function dynamically which takes some
parameters ?
<html>
<head>
<script>
doSomething = function(x)
{
alert(x);
}
reattach = function()
{
// doesn't work
document.getEle mentById("btnOn e").onclick = doSomething(200 );
// neither does this
document.getEle mentById("btnTw o").addEventLis tener("onclick" ,
doSomething(200 ), true);
}
</script>
</head>
<body>
<form>
<input type="button" name="btnOne" id="btnOne"
onclick="doSome thing(2)" value="One" />
<br />
<br />
<input type="button" name="btnTwo" id="btnTwo" onclick="reatta ch()"
value="Dynamic" />
</form>
</body>
</html>
By using the first syntax I just end up executing the function.
By using the addEventListene r function I get some weird error like:
"uncaught exception: [Exception... "Could not convert JavaScript
argument" nsresult: "0x80570009 (NS_ERROR_XPC_B AD_CONVERT_JS)"
location: "JS frame ::"
Any help is greatly appreciated.