views:

476

answers:

1

Hi all, I'm using this script (http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/) to valdate my form etc, which also has a submit function.

Here's the code which sends the form to be processed:

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() {}
});

But I have this code which warns if you haven't filled out all the fields..

jQuery("#adminForm_1").submit(function () {

    var empty = false;
    jQuery(":input", "#adminForm_1").each(function() {
        empty = (jQuery(this).val() == "") ? true : empty;
    });
    if(empty) {
        var empty_ok = confirm('You have not filled out all of the fields, do you wish to continue?');
        return empty_ok;
    }

});

Currently when you click "Cancel" it still submits the form.. how can I change the code to make sure when you hit cancel it doesn't submit the form?

+1  A: 

if one field is empty it will set it to true, then if a later one is not empty it will re-set it to false.

you should check if empty is true already, or return false on the first true assignment . that or you can rely on using an errors array and populate it, see if it has a .length, if it does then do the confirm stuff.

meder
Ok I get what you're saying, but not sure how to do it.. lol
SoulieBaby