Reputation: 89
I'm using a form to help determine the strength for an action in a game I'm making a plugin for. The player fills in some form fields and selects 1 value from a drop down and then clicks calculate. The result if I use an actual calculator is what I expected but, the result from my javascript function is not. I've been wrestling with it for a while but, can't seem to work out why it's failing to calculate correctly. Below is the function:
function wgtcalc() {
document.wgtcalc.strDSAtk.value =
(document.wgtcalc.strBaseSpeed.value * document.wgtcalc.strAltitude1.value) +
(document.wgtcalc.strBaseSpeed.value * document.wgtcalc.strAltitude2.value) +
(document.wgtcalc.strDistance.value / document.wgtcalc.strFullSwing.value);
}
Upvotes: 0
Views: 76
Reputation: 15
Try:
function wgtcalc() {
document.wgtcalc.strDSAtk.value =
( Number(document.wgtcalc.strBaseSpeed.value) *
Number (document.wgtcalc.strAltitude1.value)) +
( Number (document.wgtcalc.strBaseSpeed.value) *
Number (document.wgtcalc.strAltitude2.value)) +
( Number (document.wgtcalc.strDistance.value) /
Number (document.wgtcalc.strFullSwing.value) );
}
As pc-shooter pointed out you're doing a calculation on strings.
Upvotes: 1