Here are some input fields with different IDs:
<tr>
<td><input type="number" id="cell1" ></td>
<td><input type="number" id="cell2" ></td>
<td><input type="number" id="cell3" ></td>
<td><input type="number" id="cell4"></td>
<td><input type="number" id="cell5"></td>
<td><input type="number" id="cell6"></td>
<td><input type="number" id="cell7" ></td>
<td><input type="number" id="cell8" ></td>
<td><input type="number" id="cell9" ></td>
</tr>
I am looking to restrict the user from entering certain numbers by using jQuery. Here is an example of what I have tried:
for(var i = 0 ; i <= 81 ; i++) {
$(document).ready(function () {
$("#cell" , i).change(function () {
var n = $("#cell",i).val();
console.log($("#cell", i));
if (n < 1)
$("#cell", i).val(1);
if (n > 9)
$("#cell" , i).val(9);
});
});
}
However, this code does not recognize the IDs. How can I pass the variable i to "#cell"?