I’d like to intercept the onclick event of a button (not submit) before the page posts back from the onclick.
I’m having some trouble:
$(document).ready() { function() {
function validate() {
...
}
var oldOnClick = $("input[value=OK]").attr("onclick");
$("input[value=OK]").attr("onclick", "if(!validate()) { return false; }" + oldOnClick));
});
If you still want to handle the button click event instead of the form submit event as all suggested, you could do something like this, using an anonymous function, to call your oldOnClick function, preserving the context and the event argument: