I have my form broken up into sections, and I’m trying to have a script check the number of fields empty in each section. Previously I had written an array with the id’s of each section and had it cycle through that array, but i’d like to find a more universal solution that doesn’t depend on predefined data.
at first I was trying .find() like so
function blankFields(section){
var totblank = 0;
var inputs = $('#' + section).find('input');
$.each(inputs, function(){
if(this.val() == '') { totblank++; );
}
when that didn’t work i tried .serializeArray()
function blankFields(section){
var totblank = 0;
var inputs = $('#' + section + ' input').serializeArray();
$.each(inputs, function(i, field) {
if (field.value == '') { totblank++; }
});
and it gets followed up with
if(totblank > 0){
$("#"+section+"B").html(totblank+" Empty");
} else {
$("#"+section+"B").html("All full!");
}
}
section is the id of a div, the div has a table with form inputs.
This is my first time using these functions so I’m not really sure where I’m going wrong. Feels like I’m expecting the output to be something its not.
There are a few syntax errors in your code. Fixed: