JQuery.Validate error message on top of form

I was wondering how to display a single error message above the form instead of individual field messages. how this form has http://jquery.bassistance.de/validate/demo/marketo/step2.htm

I know that this has something to do with the pens, but not quite exactly how and where to put them

    <script>
    $(document).ready(function(){
    $("#valform").validate();
    });
    </script>

this is the code that uses all default checks

+5
source share
1 answer

You must use for this function invalidHandler. Something like this should do:

$("#myform").validate({
    invalidHandler: function(form, validator) {
        var errors = validator.numberOfInvalids();

        if (errors) {
            $("#error-message").show().text("You missed " + errors + " field(s)");
        } else {
            $("#error-message").hide();
        }
    }
});

Example: http://jsfiddle.net/KheRr/1/

, "" :

$("#myform").validate({
    invalidHandler: function(form, validator) {
        var errors = validator.numberOfInvalids();

        if (errors) {
            $("#error-message").show().text("You missed " + errors + " field(s)");
        } else {
            $("#error-message").hide();
        }
    },
    messages: {
        field1: {
            required: "" // You'll have to do this for each field and validation type.
        }
    }
});

: http://jsfiddle.net/KheRr/2/

+3

All Articles