最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jquery validate plugin, display one error at a time with css - Stack Overflow

programmeradmin4浏览0评论

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

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

Share Improve this question edited Dec 3, 2010 at 7:05 dave asked Dec 3, 2010 at 6:12 davedave 1,6795 gold badges24 silver badges32 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 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 !

$("#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

发布评论

评论列表(0)

  1. 暂无评论