I’m trying to call another jQuery function if confirm is true, here’s the code:
jQuery("#adminForm_1").submit(function () {
var empty = false;
jQuery(":input", "#adminForm_1").each(function () {
empty = (jQuery(this).val() == "") ? true : empty;
});
if (empty) {
if (confirm('You have not filled out all of the fields, do you wish to continue?')) {
jQuery("#adminForm_1").validationEngine({
ajaxSubmit: true,
ajaxSubmitFile: "/index.php?option=com_database&view=tripdetails&Itemid=12&client=1&task=save",
ajaxSubmitMessage: "Client Trip Details Saved",
inlineValidation: false,
success: false,
failure: function () {}
});
} else {
return false;
};
}
});
^^ the above code doesn’t work, but you’ll see what I’m trying to do..
You need to prevent the browser’s default action on the form, which is to submit it to the server the traditional way. Either
return falseat the end of your submit handler, or pute.preventDefault()at the beginning:or:
See
preventDefault:As as side-note
return falsehas the same effect aspreventDefaultplus it stops the bubbling of the event to parent elements. jQuery’s mechanism for achieving that is in the stopPropagation method. In other words,return false=e.preventDefault + e.stopPropagation