Imagine you have a button like this:
<input name="myButton" type="button" value="button" onclick="return test();" >
where the test functions is as follows:
function test(){
// do something
return true; // based on some logic return boolean
}
Now let's say,I don't know what is set for the onclick event, and at runtime I need to read the function or any code set to onclick and run it. Here is an example:
var btn = getElementById('myButton');
var btnOnClickFunc = btn.onclick;
if (btnOnClickFunc) {
// do something
}
I know this doesn't work, and that's actually my question. How can I read the button's onclick event in this example at runtime?
An example of this case is when the onclick is attached to the button later using jQuery.