0

Here is my Fiddle

Here the validation should happen once the button is clicked, it is ok. But i have written the validation for field 1, field 3.

Once i have pressed the button it is showing the validate error for first field only and the field 3 error is displayed only when i keypress the field 3.

Note : It is working in local but while i use the jsfiddle it is not working

The below script should be added to work in local

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="http://expirebox.com/files/88b64e3d9a74823c8b1e6b8f60091917.js"></script>

What is the mistake in the validation and how can i fix this ?

1
  • Fiddle has Only 1 textbox Contrary to your question where there are 3 textboxes Commented Nov 13, 2014 at 4:48

2 Answers 2

1

Change from id=... to name=... for field1:

     Field 1: <input name="field1" type="text" class="required">

And the result is a working demo.

DEMO

And with field2 and field3:

DEMO

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

5 Comments

PLease find this fiddle jsfiddle.net/KLrs6/581
Yes, while i change from id to name it works , And may i know the reason why we use name instead of id ?
The validate plugin like form submission uses the name attribute, not the id attribute. Any particular reason you want to use id's exclusively?
Great! Just remember that the keys field1.... in the validate method refer to name attributes.
You're welcome. Glad I could be of help.
1

Check FIDDLE

Use name attribute in validate NOT ID,Check code

<form id="form1" name="form1"> 
     Field 1: <input id="field1" name="field1" type="text" class="required"><br>
     Field 2: <input id="field2"  name="field2" type="text" class="required"><br>
    Field 3: <input id="field3"  name="field3" type="text" class="required"><br>
</form>

<div>
    <input id="btn" type="button" value="Validate">
</div>

//JS

$(document).ready(function() {
    $("#form1").validate({
        rules: {
            field1: "required",
            field2: "required",
            field3: "required"
        },
        messages: {
            field1: "Please specify your name",
            field3: "Please specify your name"

        }
    })

    $('#btn').click(function() {
        $("#form1").valid();
    });
});

8 Comments

Just now i realized that jsfiddle.net/KLrs6/582 Anyways thanks +1
@BizDev Welcome ,and please work on improving english a little .Thanks.
Ahm, thanks. You mean the way i convey or my grammar ?
@BizDev Both -> Just now i realized that jsfiddle.net/KLrs6/582 Anyways thanks +1 Here , 1)You need to Capitalize 'I' 2)I realized that jsfiddle.net ,This is incomplete sentence. you should use I realized that jsfiddle.net is working properly. like this 3)Before Anyway use Fullstop "." as you completed 1st sentence.4)After Anyway thanks give fullstop , like Anyway thanks..
Thanks. I will correct myself.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.