I have the following function that is sent to call when I enter the page, but at that time I still do not have the variables full with values, since they load up to fill a few combos and reload the page.
The first time you enter, the field inputTotal
shows NaN
I imagine because there is nothing even in the variable, and when you fill a few combos and the page is loaded, it is already shown in value of variable total
in my input
function calcularTotal(){
var valor = parseInt($(#inputCalculo1).val());
var valor1 = parseInt($(#inputCalculo2).val());
var valor2 = parseInt($(#inputCalculo3).val());
var total = valor + valor1 + valor2;
document.getElementById("inputTotal").value=total;
}
How can I validate it so that it does not appear in my input the first time it enters the page, but it is shown in blank nothing else, and when filling in the data and loading the page, it already shows the value of the variable
How could I do it?
Is it ok that I do the parseInt
?, the values that I have inputCalculo1, inputCalculo2, y inputCalculo3
are numeric values, and is that if I do not put it in parseInt when doing the sum, do not add them, just put together the numbers
I hope you can support me, thanks