"I'm trying to check two inputs with the same name with jquery validator ..."
<input type='text' name='inp_text'/> <input type='text' name='inp_text'/>
"but when I run this code, it only checks the first inputs and the second inputs are just ignored"
You cannot have two input type="text" fields with the same name , or this plugin will not work properly. The name attribute must be unique. (The only exception to name , which is unique, is that the βgroupsβ of flags or radio inputs will have the same name , since the corresponding representation is a single data point. However, the name must be unique for each group of flags and radio elements.)
"what should I change ...?"
Make each name attribute unique.
<input type='text' name='inp_text[1]'/> <input type='text' name='inp_text[2]'/>
Then use the "starts with" selector, ^= ...
$("[name^=inp_text]").each(function () { $(this).rules("add", { required: true, checkValue: true }); });
Working DEMO: http://jsfiddle.net/PgLh3/
NOTES . You can also customize id elements using the rules('add') method, but nothing has been decided for this case, because the plugin still requires a unique name for each input .
source share