Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call a function on success jQuery validation plugin when all validation are done

Tags:

jquery

<script id="demo1" type="text/javascript">

jQuery(document).ready(function () {
    var validator = jQuery("#login").validate({
        rules: {
            pwd: "required",
            log: {
                required: true,
                email: true,
            },
        },
        messages: {
            pwd: "Please enter password",
            log: {
                required: "Email is required",
                email: "Please enter a valid Email Address",
            }
        },
        errorPlacement: function (error, element) {
            if (element.is(":radio"))
                error.appendTo(element.parent().next().next());
            else if (element.is(":checkbox"))
                error.appendTo(element.parent().next("span#error"));
            else
                error.appendTo(element.parent().next("div#error"));
            //error.appendTo ('div#error').show().fadeOut(4500);
        },
        success: function (label) {
            // set &nbsp; as text for IE
            label.html("&nbsp;").addClass("checked");
        }
    });
});
</script>

I have this script to validate the form, this script runs well for my form, i want to run a function when all the fields are validated , means inputs are correct , if i call function inside success then it runs everytime when a single input is validated, but i want to call it after all the inputs are correct, please help, i am trying different ways from last one hour with no result..

like image 543
Ankit Avatar asked Nov 14 '22 02:11

Ankit


1 Answers

below code work for me

jQuery(document).ready(function() {

var validator = jQuery("#login").validate({

    rules: {

            pwd: "required",

        log: {

            required: true,

            email:true,

        },

    },

    messages: {

        pwd: "Please enter password",

        log: {

            required: "Email is required",

            email:"Please enter a valid Email Address",

        }

    },

    submitHandler: function(form) {
        // call your function
        $("#login")[0].submit(); 
    }

});

});
like image 193
Saheb Mondal Avatar answered Dec 27 '22 08:12

Saheb Mondal