I know there are numbers of answers available for this question but I want to validate whole form with dynamic input fields coming from database like Google Forms
.
Html
<div class="rs_card"><span style="font-size: 1em;">How to create website like programmer?</span><div class="col-3" style="margin-top: 5%"><input type="text" placeholder="Placeholder Text" class="input_field required"><span class="focus-border"></span></div></div>
<div class="rs_card"><span style="font-size: 1em;">How to create art like painter?</span><div class="col-3" style="margin-top: 5%"><input type="text" placeholder="Placeholder Text" class="input_field required"><span class="focus-border"></span></div></div>
<div class="rs_card"><span style="font-size: 1em;">How to create transition effect like materialize css</span><div class="col-3" style="margin-top: 5%"><input type="text" placeholder="Placeholder Text" class="input_field required"><span class="focus-border"></span></div></div>
JS
$(document).ready(function(){
$('input.required').each(function(){
$(this).on('input', function(){
if($(this).val() == ''){
$(this).parents('div.rs_card').addClass('invalid_card');
} else{
$(this).parents('div.rs_card').removeClass('invalid_card');
}
});
});
});
I will also tried keyup
instead of input
but not working.
This line of code below is working fine (tested with other condition).
$(this).parents('div.rs_card').addClass('invalid_card');
This code isn't working, can anyone tell me what is wrong with this code.