1

I'm working with my code that allows to user to add more fields then It will validate if the user entered data.

My code works but I want to change the message of error..

Instead of displaying "This field is required."

I want to display "Please select an option."

How can I do it with changing the background of blank inputs?

Here is my jsfiddle: http://jsfiddle.net/ThE5K/6/

$(document).ready(function () {

    // MODE 1
    var numberIncr = 1;
    $("#addInput").on('click', function () {
        $('#inputs').append($('<input class="comment required" name="name[' + numberIncr + ']" />'));
        numberIncr++;
    });

    $('form.commentForm').validate();
});

<form class="commentForm">
    <div id="inputs"></div>
    <input type="submit" /> <span id="addInput">add element</span>

</form>

1 Answers1

0

this links will be helpful for you

jQuery validation: change default error message

jQuery Validation plugin - Custom message

$("#form")
.validate({
    rules: {
        password: "required",
        username: {
            required: true,
            minlength: 3
        }    //your rules as per your requirements
    },
    messages: {
        password: "Password is required",
        username: {
            required: "Field Username is required",
            minlength: "Field Username must contain at least 3 characters" 
        }
});
Community
  • 1
  • 1
Sagar Naliyapara
  • 3,971
  • 5
  • 41
  • 61