I have basic javascript code to generate input text areas as below
$("#btnAdd").click(function (e) {
var itemIndex = $("#container input.iHidden").length;
e.preventDefault();
var newItem = $("<span class='badge badge-success'>" + itemIndex + "</span> <input id='Interests_" + itemIndex + "__Id' type='hidden' value='' class='iHidden' name='Interests[" + itemIndex + "].Id' /><input type='text' id='InvoiceNumber_" + itemIndex + "__InvoiceNumber' placeholder='Fatura Numarası' name='[" + itemIndex + "].InvoiceNumber'/> <input type='text' id='Interests_" + itemIndex + "__InterestText' placeholder='Fatura Tutarı(TL)' name='[" + itemIndex + "].Amount'/> <br /><br />");
$("#container").append(newItem);
});
And i have a form for this dynamic fields. I am using jquery validator for this form for other elements. Now i also want to validate this dynamicly created fields.
For static fields here my working validation scripts.
$('#frm_register').validate({
focusInvalid: false,
ignore: "",
rules: {
FirstName: {
required: true
} ....
And here sample of my dynamic fields.
<input type="text" id="InvoiceNumber_0__InvoiceNumber" placeholder="Fatura Numarası" name="[0].InvoiceNumber">
<input type="text" id="Interests_0__InterestText" placeholder="Fatura Tutarı(TL)" name="[0].Amount">
<input type="text" id="InvoiceNumber_1__InvoiceNumber" placeholder="Fatura Numarası" name="[1].InvoiceNumber">
<input type="text" id="Interests_1__InterestText" placeholder="Fatura Tutarı(TL)" name="[1].Amount">