1
I have the following fields from the database:
<?php
while($peListar = mysqli_fetch_object($sqlListar){
.....
$listar .= "<td style='".$fundo."'><input type='text' name='ValorI[]' class='md-form-control' value=''></td>";
$listar .= "<td style='".$fundo."'><input type='text' name='ValorII[]' class='md-form-control' value=''></td>";
$listar .= "<td style='".$fundo."'><input type='text' name='ValorIII[]' class='md-form-control' value=''></td>";
$listar .= "<td style='".$fundo."'><input type='text' name='ValorFinal[]' class='md-form-control' value=''></td>";
.....
}
?>
But I would like to count how many empty fields you have, that is, how many fields were not typed by the user. It is understood that I do not want a validation of fields ;) but only count the total of how many fields have not been filled in. I tried to use the code below, but it didn’t work:
....
$(\"[name^='ValorI']\").on(\"input\", function(){
.....
var myForm = this.form;
var vazios = 0;
for(var i = 0; i < myForm.elements.length; i++) {
if (myForm.elements[i].value === \"\")
vazios += 1;
}
alert(vazios);
....
Including the "valorFinal"?
– Sam
Hello dvd. No valueFinal. Actually it is upon your solution that you passed me in the old post. As is another subject, I opened this post.
Seria nessa linha: $("[name='ValorFinal[]']", parent).val((valor1+valor2)/3);
where the value3
, would be the value of the fields filled, ignoring the empty fields, ie if only fill 02 fields, would be2
.– user24136
Oh yes, I posted the answer counting all the fields in the table... but you just want the line, it’s not even?
– Sam
I edited the answer. In your case it would be "count filled fields" and not "empty"... in this case just remove the
!
of!$(this).val();
...– Sam