G
getsanjay.sharma
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.getElementById("btnOne").onclick = doSomething(200);
// neither does this
document.getElementById("btnTwo").addEventListener("onclick",
doSomething(200), true);
}
</script>
</head>
<body>
<form>
<input type="button" name="btnOne" id="btnOne"
onclick="doSomething(2)" value="One" />
<br />
<br />
<input type="button" name="btnTwo" id="btnTwo" onclick="reattach()"
value="Dynamic" />
</form>
</body>
</html>
By using the first syntax I just end up executing the function.
By using the addEventListener function I get some weird error like:
"uncaught exception: [Exception... "Could not convert JavaScript
argument" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)"
location: "JS frame ::"
Any help is greatly appreciated.
parameters ?
<html>
<head>
<script>
doSomething = function(x)
{
alert(x);
}
reattach = function()
{
// doesn't work
document.getElementById("btnOne").onclick = doSomething(200);
// neither does this
document.getElementById("btnTwo").addEventListener("onclick",
doSomething(200), true);
}
</script>
</head>
<body>
<form>
<input type="button" name="btnOne" id="btnOne"
onclick="doSomething(2)" value="One" />
<br />
<br />
<input type="button" name="btnTwo" id="btnTwo" onclick="reattach()"
value="Dynamic" />
</form>
</body>
</html>
By using the first syntax I just end up executing the function.
By using the addEventListener function I get some weird error like:
"uncaught exception: [Exception... "Could not convert JavaScript
argument" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)"
location: "JS frame ::"
Any help is greatly appreciated.