var dml = 30
var dd = parseFloat(document.getElementById("DriverD").value) <----- Only numbers like 10
var dm = dd-dml
alert((dd - dml) * 0.75) <----- This works
alert(dm * 0.75) <----- This returns NaN
alert(typeof(dm)) <----- This show that dm is a Number
I'm not sure why I keep getting NaN. I already tried parseFloat
and parseInt
but still showing NaN when multiplying a variable (dm) which consists of variables (dd-dml). dm is the result of subtracting dml with dd or 10-30. Please share your solutions.
I'm new here and I need help, please don't troll :) I am trying to add a cost calculator to my website.
It seems fine to me.
I want to tell another possible problem: You dont check if document.getElementById("DriverD").value
is a number or not. If a user enters a string or other type, it will cause a problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With