1

I am using the jQuery.validate plugin but I would like to change the background color of the input field that has failed rather than displaying a message? Is there anything like this already built in to the plugin or will I need to add something to make it work?

Here's the code I have so far:

$("#myForm").validate({
    debug: false,
    rules: {
        YourName: {
            required: true,
        },
    },
//I want to highlight the failed element here by changing the background color
    submitHandler: function(form) {

    $.post('projectform.php', $("#myForm").serialize(), function(data)
        {
          $('#myDiv').html(data);       
        });
      }

});
0

2 Answers 2

3

try setting custom functions like

$("#myForm").validate({
            errorPlacement: function(error, element){
                element.addClass('errorClass');
            },
            unhighlight: function(element, errorClass, validClass) {
               $(element).removeClass('errorClass');
            }
}

where errorClass is a class added to the inputs when it's not valid

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

Comments

0

refer this link

jQuery validation plugin - no error messages instead custom backgrounds

you can change ".error" class to customize your input field

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.