You need to place the code that is run under those buttons within their own functions so that they can be called either individually under the #Save
or #Submit
buttons, or together under the BtnClick
function. Try this:
<form id="myForm">
<!-- your fields ... -->
<input type="button" id="postForm" />
</form>
function submitHandler(callback) {
// make the AJAX call, using the callback parameter as the callback:
$.ajax({
url: 'foo.com',
data: { foo: 'bar' },
success: function() {
callback && callback();
}
});
}
function saveHandler() {
// post the form
$('#myForm').submit();
}
function formHandler() {
// do both
submitHandler(saveHandler);
}
$("#Submit").click(submitHandler);
$("#Save").click(saveHandler);
$('#postForm').click(formHandler);