i am using (for) to add multiple input form
i want to check this forms with keyup
but it always check the first form only
here is code
for (i = 0; i < 5; i++) {
$('input[name*="morein"]').keyup(function () {
var value = $(this).val();
var moreincheck = $("#moreincheck");
if (value > 60) {
moreincheck.css('display', 'block');
moreincheck.text("error cant add more than 60");
} else {
moreincheck.css('display', 'none');
}
}).keyup();
$("#divTxt").append('<inputname="morein[]" type="text" />' + '<span id="moreincheck" class="checkerror"></span>');
}
IDs have to be unique! (and you noticed why). Furthermore you are re-adding the same event handler to all
input[name*="morein"]in each iteration.It is better to create the elements first, bind the event handler and use DOM traversal to find the corresponding element. For example: