0

http://jsfiddle.net/nXqd/qC2Ya/6/

Take a look at the jsfiddle. When I enter wrong data in two inputs and clicking submit, I only receive the error message on the first one. Now I want two of them which have the name attribute in the form displayed as well.

In this example, I use the same name on purpose to get these values on the backend easier. I just loop through the list and get all information.

3 Answers 3

2

You are doing it wrong. You have added same name for both fields. Same name attributes are used to combine the fields in a group. You have to use class based validation.

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

2 Comments

actually, I use the same name on purpose which is getting information easier on the back end. If I change to using class based - ( use $.each ?, tell me if I'm wrong ). A group of fields will be added at run time so I have to bind the validate for them ? ( a group may have 6 fields )
Yes you are wrong. class based validation doesn't need $.each. its quite simple. if you could see the validation plugin demo. Its fairly simple. and its the best choice if you have dynamically added fields
1

working demo http://jsfiddle.net/xr5g6/1/

Hope it fits your needs. :)

code

$("form").validate({
    rules: {
        number: {required: true, range: [1,2]},
        number2: {required: true, range: [1,2]}
    }
});

html

<form name="myForm">
<fieldset>
<legend>My Form</legend>
    <label for='number'>Number</label>
    <input name='number'class='required'/> <br />
    <label for='number'>Number</label>
    <input name='number2' class='required'/>
    <label for='change-range'>Max range</label>
    <input name='change-range' class='required'/>
</fieldset>
<input type="submit">
</form>
​

Comments

0

You should use different name attriburtes for different inputs.

Demo: http://jsfiddle.net/xYTNw/

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.