in a form, onkeypress, I call this function:
function calculate() {
var subtotal = parseInt(document.form1.product1.value) * product1 +
parseInt(document.form1.product2.value) * product2 +
parseInt(document.form1.product3.value) * product3;
alert(typeof subtotal);
alert(subtotal);
var total = subtotal + parseInt(document.form1.shipping.value);
document.form1.subtotal.value = subtotal;
document.form1.total.value = total;
}
When I alert the typeof subtotal, I get number. But then when I alert the subtotal, I get NaN. What am I missing? Thanks.
typeof NaNisnumberin JavaScript.NaNis toxic, if it is part of any arithmetic, the result isNaN.The most probable reason is that
parseInt()is returningNaN. Are those elements’valueproperty an empty string?