I have the following code:
var inputsArray = document.getElementsByTagName('input');
function computeTotal() {
var tot = 0;
tot += parseFloat(inputsArray[0].value);
tot += parseFloat(inputsArray[1].value);
tot += parseFloat(inputsArray[2].value);
inputsArray[3].value = tot;
}
<input type="text"></input>
<input type="text"></input>
<input type="text"></input>
<input type="text" disabled></input>
<button type="button" onclick="computeTotal()">Calculate</button>
It calculates fine when a number is entered in all three boxes, but I would like it to calculate even if a box is left empty, when in fact returns NaN.
P.S.: I know I could use a "for" loop and the isNaN() method to skip blank inputs, but I'm really looking for a solution for adding the inputs one by one.
I do not want to convert the NaN to 0.