2
good evening, I’ve been trying to calculate several fields in javascript validating if they are with values, I’ve done something similar in javaSE, but I realized that it doesn’t work the way I imagined in javascript. Basically what I want is to calculate 10 fields, validating if they have values, and if they are not ignored
Code of what I’ve tried to do
// Calcula total da nota
function calcularTotalNota()
{
    // Campos
    var valorPrimeiroProduto = document.getElementById("total1").value;
    var valorSegundoProduto = document.getElementById("total2").value;
    var valorTerceiroProduto = document.getElementById("total3").value;
    var valorQuartoProduto = document.getElementById("total4").value;
    var valorQuintoProduto = document.getElementById("total5").value;
    var valorSextoProduto = document.getElementById("total6").value;
    var valorSetimoProduto = document.getElementById("total7").value;
    var valorOitavoProduto = document.getElementById("total8").value;
    var valorNonoProduto = document.getElementById("total9").value;
    var valorDecimoProduto = document.getElementById("total10").value;
    var totaNota = document.getElementById("totalNota").value;
    // Calcula todos os campos
    if(!valorPrimeiroProduto == null)
    {
        totaNota += valorPrimeiroProduto;
    }
}
The result should be shown in totalNota
Do you want to deny equality with null? I think maybe it is confusing in the precedence of operators; puts
if (! (valorPrimeiroProduto == null) ) {, or uses the same different operatorif (valorPrimeiroProduto != null) {– Jefferson Quesado