3

I want to know that how can I display the error messages on the bottom of the screen by using the jquery,validator plugin

also it's suppose to display the one error at a time.

for eg:-

name:- first error will be of name
email:- once name is validated then email's error will be displayed
website:-finally website's error.

And how to highlight the textbox of the field one by one same style:

< input type="text" name="name" >
< input type="text" name="email" >
< input type="text" name="website" >

< div id='error' >if name is blank then display only name is blank, if not then check for email and after that website< /div >

I don't know the how the whole coding is going to look like.

Please provide the coding snippet.

Thanks in advance

Dave

2 Answers 2

8

Try this:

$("#myForm").validate({
    // Validation rules and messages go here

    showErrors: function(errorMap, errorList) {
        $("#myForm").find("input").each(function() {
            $(this).removeClass("error");
        });
        $("#myErrorContainer").html("");
        if(errorList.length) {
            $("#myErrorContainer").html(errorList[0]['message']);
            $(errorList[0]['element']).addClass("error");
        }
    }
});

This will place one error at a time inside an element that has a myErrorContainer ID, and at the same time will highlight the element that is causing the error by adding a .error class to it.

Hope this helps !

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks FreeOne, The code snippet is working, but it's suppose to show the one error at a time, once the first validation is clear, then move to the others, also hightlighting is happening to all of them.
Yes' it's displaying the one error at a time, but hightlight is not happening at all :(
@dave - Please see the updated answer. This should work properly now.
@dave: glad to be of help ! :)
1
$("#myform").validate({
  wrapper: "li",
  errorPlacement: function(error, element) {
     error.appendTo('#errordiv' );
   },
   debug:true
 })

replace errordiv with the id or class or whatever selector you have for the element you want to put the errors in

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.