1

Using JQuery Validate, I can set easily messages when something goes wrong:

<input class="required" id="pwd" name="pwd" type="password" title="ERROR here" />

How can I make this the default message when there is no error and set another message when there is an error? Example:

<input class="required" id="pwd" name="pwd" type="password" title="Write your password" />
....

$('#form').validate({
    rules: {
        pwd: {
          SET MESSAGE IF ERROR
        }
    }
});

Edit: I'll try to explain better: I need first no message, when the user sets focus to an input I want to show a "status" message (like "Write your password") and last, if the text is wrong, show an error message (like "enter more than 8 characters").

1 Answer 1

1

Ok try this:

$('#form').validate({
    rules: {
        pwd: {
          $('label[for=pwd]').html('ERROR HERE');
        }
    }
});

I don't know what plugin you're using for the validation but this is how you would update a label assigned to that input field.

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

3 Comments

No, what I want is to show a message ("write your password") when the user puts focus in my input field and put another message if the field don't validate ("you must write at least 8 characters" or "this field is mandatory").
Where do you want to show it? Do you have a div container setup for these messages, or do you want an alert?
Sorry, I'll explain better.. By default, JQuery validate shows the parsing errors in a label. This is ok for me. My problem is that I want to show a message if there is no error (while user is typing) and change this message if user clicks on submit and there is a validation error. It's ok also if the first message is hiden when the input loses the focus.

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.