I have a dynamic input boxes having the following ids, points0, points1,points2 etc. I want to make sure that these input boxes shoould match only numbers. So I used the following code but in console it always shows
TypeError: $(...).val(...) is undefined
So I used the following code. I am looping over input text boxes.
var result = document.getElementsByTagName("input");
for (var j = 0; j < result.length; j++) {
var points = 'Enter a valid point.';
var regex = '/^[A-Za-z!@#></!?\$%\^\&*\)\(+=._-]+$/g';
if ($("#points" + j).val().match(regex)) {
$('#points' + j + ' + span').html('');
$('#points' + j).after('<span class="' + errTextboxClass + '" style="color:#e03b3b;">' + points + '</span>');
$('#points' + j).focus();
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
In my Laravel blade I am looping some answers,
@if($ans)
@for($j=0;$j<count($ans) ;$j++)
<input class="form-control " name="points[]" id="points{{$j}}" placeholder="POINTS" value="<?php echo $ans[$j]['points'];?>">
@endfor
@endif