Is there another way to change the action of an event handler (such as onClick) for an element via script besides assigning that element’s onclick “property” to a method?
i.e.
[code]
function test1() {
alert(“test 1”);
}
function test2() {
alert(“test 2”);
}
function change() {
document.getElementById(“myLink”).onclick = test2;
}
<p><a href=”#” id=”myLink” onclick=”test1();”>test</a></p>
<p><a href=”#” onClick=”change();”>change</a> </p>
Is there a way to assign the new action by supplying the text that would be in the event handler? As an example, if I had the following code:
[code]
<input type=”button” name=”viewBtn” id=”viewBtn” value=”View” onClick=”openWin(‘file.jsp?fieldName=origField&propName=origProp’,’editwin’,’width=500,height=500,scrollbars’);”>
but wanted to change the code in the onClick handler to be:
onClick=”openWin(‘file.jsp?fieldName=[B]newField[B]newProp
Can I do this by somehow assigning a string to the onclick property?
i.e.
[code]
document.getElementById(“viewBtn”).onclick = someString;
// someString = “openWin(‘file.jsp?fieldName=newField&propName=newProp’,’editwin’,’width=500,height=500,scrollbars’)”;