I have a view
with 3 divs
and 20 input number
on each line of my div and a input submit
. Each line comes from my bank.
(For this example I will use only 3% with%).
These my inputs number
are as if they were 3 categories of anything, that is, I will exemplify here in SCHOOL NOTES and the CATEGORIES will be the STUDENTS.
As I use ASP .NET MVC to do the VIEW then I do not use
divs
, but<input>
.. As for me, it makes no difference I write with @Html, because doubt does not refer to this , so I wrote with@Html.TextBox
to facilitate.
function validacao(contagem){
var botao = false;
var cor = "black;"
var total = 0;
/*
Alem da contagem, eu passo outros parametros, para que eu consiga realizar a
minha soma, então as removi, pois nao acho necessario para minha duvida.
*/
if (total < 9) {
botao = false;
cor = "black";
} else {
botao = true;
cor = "red"
}
for (var i = 0; i <= contagem; i++) {
$("#meusInputs"+i).css('color', cor);
$("#btn-salvar").prop('disabled', botao);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><h3>MediadeNotas</h3><divclass="form-inline">
<div class="form-inline">
<p> Maria </p>
<input type="number" class = "form-control" id="meusInputs"+contagem onblur="validacao("+@contagem+")">
<input type="number" class = "form-control" id="meusInputs"+contagem onblur="validacao("+@contagem+")">
<input type="number" class = "form-control" id="meusInputs"+contagem onblur="validacao("+@contagem+")">
</div>
<div class="form-inline">
<p> Joao </p>
<input type="number" class = "form-control" id="meusInputs"+contagem onblur="validacao("+@contagem+")">
<input type="number" class = "form-control" id="meusInputs"+contagem onblur="validacao("+@contagem+")">
<input type="number" class = "form-control" id="meusInputs"+contagem onblur="validacao("+@contagem+")">
</div>
<br/>
contagem++ // Usado no foreach da minha view ASP .NET MVC <br/>
<input type="submit" value="Salvar" id="btn-salvar">
While completing this page, I perform a validation in which the sum of a line does not exceed 8, if it exceeds the text of all% of that line becomes red and <input>
is disabled.
It's validation I perform, obligatorily, on the onblur of EVERY inputs number
.
However, as I continue to fill in and validate (from the other submit
) become correct (ie, below 8), my input number
is back enabled and my doubt is:
How do I, if there is at least a
inputs number
with the text in red, mysubmit
continue DISABLED?