[jQuery] [validate] Validating an input with a dynamic name
I've seen this discussed before, but I'm not able to put the pieces
together.
I have a form that allows a user to add new rows to the form. Each
row contains an input box and a hidden field
<td><input name="1useThisRecord" id="1useThisRecord" type="hidden"
value="1"></td>
<td><input class="inputFormulary" name="1Name_Strength"
id="1Name_Strength" type="text" value=""></td>
When the user clicks a button elsewhere on the page a new row is added
and the names are incremented accordingly:
<td><input name="2useThisRecord" id="2useThisRecord" type="hidden"
value="1"></td>
<td><input class="inputFormulary" name="2Name_Strength"
id="2Name_Strength" type="text" value=""></td>
Another button allows them to "use" a field by turning the hidden
field to 0 or 1.
What I'm looking for (in plain speak):
For each input box
If (index)useThisRequired = 1, (index)Name_Strength must have a
value.
It seems to me that I would be able to add a validation method to the
class="inputFormulary":
...class="inputFormulary required: function(element) {return $
("#<index>useThisRecord").val() == 1;}" name="1Name_Strength"...
But this is my first attempt using this plugin, and I get lost pretty
fast.
Any ideas? Thanks!