0
As I would for a text field to receive values up to 10.0 and to have a mask like this: 1.0, 2.3, 10.0, that is, when the value is less than the limit 10.0, the decimal has only 1 number. Is this possible with Jquery? I have a script that sums all fields, you can include inside this script?
<input type='text' name='NotaI[]' id='justificativa' class='mascara md-form-control' value='".$notaProvas."'>
<input type='text' name='NotaII[]' id='justificativa' class='mascara md-form-control' value='".$notaProvas."'>
<input type='text' name='NotaIII[]' id='justificativa' class='mascara md-form-control' value='".$notaProvas."'>
<script>
$("[name^='NotaI']").on("input", function(){
var parent = $(this).closest("tr");
var valorA = $("[name='NotaI[]']",parent).val() || 0;
var valorB = $("[name='NotaII[]']",parent).val() || 0;
var valorC = $("[name='NotaIII[]']",parent).val() || 0;
var valor1 = parseFloat(valorA.toString().replace(',', '.'));
var valor2 = parseFloat(valorB.toString().replace(',', '.'));
var valor3 = parseFloat(valorC.toString().replace(',', '.'));
/*
var vazios = 0;
$(":input.md-form-control").each(function(i, val) {
if ($(this).val() == '') {
vazios++;
}
});
console.log(matches);
*/
var campos = $("[name^='NotaI']", parent);
// conta apenas os vazios
var vazios = campos.filter(function(){
return $(this).val();
}).length;
var somar = ((valor1+valor2+valor3)/vazios).toFixed(1);
$("[name='NotaFinal[]']", parent).val(somar);
});
</script>
10.0, could be 10.01, 10.02, etc? Or
10.0
is the limit, that is after the flowing point nothing can be above0
, even if it is a number well "broken"?– Guilherme Nascimento
Hello William. That, 10.0 would be the limit. I will adjust my post ;)
– user24136
He can accept numbers as
9.99999998
?– Guilherme Nascimento
It would be exactly for school grade. I believe it would have to be 9.9 and 10.0.
– user24136
I get it, so decimal is always one digit, I just need to confirm this
– Guilherme Nascimento
that’s right. The decimal would be only 1 digit
– user24136