html :
<div id='myform'>
Name : <input type='text'/>
Age : <input type='text'/>
.....
<input type='button' class='mysavebutton' value='save'/>
</div>
html script :
$(document).ready(function(){
$("#myform input:button").click(function(){
//do save
alert("Save complete.");
});
});
the problem is :
how to add function to #myform input:button before “do save” without change anycode above.. (like add plugins)
i already create somthing like this
$(document).ready(function () {
$(".mysavebutton").each(function () {
$(this).data("old_click", $(this).click); // <----- here the problem #1. how to keep click function.
$(this).unbind("click").click(function () {
parent = $(this).parents("body");
$(parent).find("input:textbox").each(function () {
validate_object(this); //this function validate all textbox on body and add error class to textbox if error
});
if ($(parent).find("input:type.error").length == 0) {
//no error. than call old function
$(this).data("old_click"); //eval($(this).data("old_click"))
}
else {
//not run old_click coz error
alert("Invalid data.")
}
});
});
});
if possible, repair. if not, please give other solution. thanx
Might be a better way but this should work.
http://jsfiddle.net/GhLSS/1/