Input as array validate does not work. When I add row the validation only works for the 1st row and not for other rows.
This is my code, when I add more row.
when I add row and hit submit button, it checks only the 1st row validation, I don't know how fix this error.
function add_row() {
var rowno = $("#employee_table tr").length;
rowno = rowno + 1;
$("#employee_table tr:last").after("<tr id='row" + rowno + "'><td><input type='text' name='name[]' placeholder='Enter Name'></td><td><input type='text' name='age[]' placeholder='Enter Age'></td><td><input type='text' name='job[]' placeholder='Enter Job'></td><td><input type='button' value='DELETE' onclick=delete_row('row" + rowno + "')></td></tr>");
}
function delete_row(rowno) {
$('#' + rowno).remove();
}
$(function() {
//validation rules
$("#submitform").validate({
rules: {
"name[]": {
required: true,
},
"age[]": {
required: true,
},
"job[]": {
required: true,
}
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script>
<form method="post" id="submitform" action="javascript:void(0)">
<div id="wrapper">
<div id="form_div">
<table id="employee_table" align=center>
<tr id="row1">
<td><input type="text" name="name[]" placeholder="Enter Name"></td>
<td><input type="text" name="age[]" placeholder="Enter Age"></td>
<td><input type="text" name="job[]" placeholder="Enter Job"></td>
</tr>
</table>
<input type="button" onclick="add_row();" value="ADD ROW">
<input type="submit" name="submit_row" value="SUBMIT">
</div>
</div>
</form>
any help or suggestion will be appreciated