How would I make a text field receive values up to 10.0 and have a mask like this: 1.0, 2.3, 10.0, that is, when the value is less than the 10.0 limit, the decimal has only 1 number. Is this possible with JQuery? I have a script that adds all the fields, how do I include it 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>