Article ID: 190247
Article Last Modified on 8/8/2007
<HTML>
<HEAD>
<TITLE>Changing event handlers at run-time</TITLE>
<script language="JScript">
<!--
function test (sArgs)
{
alert ("I am test ()" + sArgs);
// this actually calls the function,
// which doesn't change it
// and causes recursion.
// btn1.onclick = test ('value 2')
// this just changes the onclick
// value to a new string,
// but doesn't change the function.
// btn1.onclick = "test ('value 2')"
}
-->
</script>
</HEAD>
<BODY>
<input id=btn1 type=button value="(JScript)Change function"
onClick="test('value 1');">
</BODY>
</HTML>
var newHandlerArg = "value 2" ;
var newFunctionBody = "test('" + newHandlerArg + "');" ;
btn1.onclick = new Function(newFunctionBody);
Additional query words: function pointer handler changing modifying dynamic
Keywords: kbaccess200fix kbcode kbhowto KB190247