This is my first post on stackoverflow, I encountered an error in the following code, when viewing the JS element / console in firefox, an error does not appear, but for some reason the output after the calculation shows an undefined / NaN error. User input is parsed in Float.
code:
function costtoShip(){ // get input var weight = parseFloat(document.getElementById("weight")).value ; var msg; var cost; var subtotal; // calculation if ( weight >= 0.00 && weight <= 150.00 ) { cost = 20.00; } else if ( weight >= 151.00 && weight <= 300.00 ) { cost = 15.00; } else if ( weight >= 301.00 && weight <= 400.00 ) { cost = 10.00; } subtotal = weight * cost ; msg = "<div> Total Weight is " + weight + "</div>" ; msg = msg + "<div> Subtotal is " + subtotal + "</div>" ; // send output document.getElementById("results").innerHTML = msg ; }
source share