I encountered an issue in my code while working on a dynamic form for age with unobtrusive client-side validation. The problem is that the validation is row-wise, but it behaves incorrectly by removing other rows' validations when I change one.
Below is the snippet of my code:
function dob_police(){
var age = document.getElementById('p_age').value;
if(age < 20){
document.getElementById('wrong_dob_alert').style.color = 'red';
document.getElementById('wrong_dob_alert').innerHTML = 'Age must be 20 above';
}
else{
document.getElementById('wrong_dob_alert').style.color = 'green';
document.getElementById('wrong_dob_alert').innerHTML = '✓';
}
}
<div class="form-group">
<label>Age</label>
<input type="number" class="form-control form-control-sm" id="p_age" name="age" required onkeyup="dob_police()" value="<?php echo $row['age']; ?>">
<small id="wrong_dob_alert"></small>
</div>