I am creating a form that has several fields, all defined as numbers using currency formatting:
CurrentBase which is the monthly pay rate which the user enters
CurrentYearly which is the annual pay rate and is calculated as CurrentBase * 12 -- this is read-only
CurrentOvertime which is an estimate based on 6% of the CurrentYearly and which the user can override.
As a OnBlur event in CurrentBase I use this code:
var cYear=this.getField("CurrentYearly");
cYear.value=this.getField("CurrentBase").value* 12;
this.getField("CurrentOvertime").value=cYear.value*0.06;
I also have a CurrentTotal field which is the sum of CurrentYearly and CurrentOvertime, set in the custom calculation script for CurrentTotal as:
this.getField("CurrentTotal").value=this.getField("CurrentYearly").val ue+this.getField("CurrentOvertime").value;
Here is the problem:
If I enter a CurrentBase, such as 1234 my script correctly calculates the CurrentYearly ($14,808.00), CurrentOvertime ($888.48) and CurrentTotal ($15,696.48) correctly.
Now if I override the CurrentOvertime using something like 555.00 the total calculates correctly, in this case $15,363.00
But if I type 555. (omitting the decimal values) my CurrentTotal displays as $14,808,555.00
This seems to be a bug. Any thoughts on why and how to fix it.
Bob
The value is treated as a string instead of a number, so it is just being
concatenated to the other value, instead of added to it.
The solution is to explicitly convert the value to a number, which can be
done in several ways. The simplest is to add a plus symbol in front of it,
like so (the brackets are not required, but they make it easier to read):
this.getField("CurrentTotal").value =
(+this.getField("CurrentYearly").value) +
(+this.getField("CurrentOvertime").value);
North America
Europe, Middle East and Africa
Asia Pacific