Copy link to clipboard
Copied
How to you troubleshoot the error "the value entered does not match the format of the field"? The message is being generated more than 50 times in the file. You have to click OK on each of the messages before you can do anything else in the file. When you edit the javascript you get the same error message but may reference another field.
Copy link to clipboard
Copied
Do you use divisions in your calculations?
Copy link to clipboard
Copied
No, just sums. See example below. Field1 is a text field with a value of "." or "yes". Fields 2, 3, and 4 are total fields of numbers. The *1 is being used to get the formatting needed of the number without decimal places.
var a=this.getField("field1");
var b=this.getField("field2");
var c=this.getField("field3");
var d=this.getField("field4");
if (a.value=="yes"){event.value=''}
else
event.value=b.value+c.value+d.value*1;
if (event.value==0||event.value=='') {event.value=''};
Copy link to clipboard
Copied
Change this line:
event.value=b.value+c.value+d.value*1;
To:
event.value=Number(b.value)+Number(c.value)+Number(d.value);
Copy link to clipboard
Copied
One needs to understand how JavaScript handles the types of string and number values and what the "+" operator does. The "+" operator is either the add or concatenate, join strings into one string, depending upon what JavaScript thinks the type of the inputs. If all the values are numbers it will perform addition, but if any of the input values is considered a string by JavaScript then that and following actions will be concatenation.
You can observe what is happening by setting the Format for the field or fields with the error to "None" and observing the result.
A numerical value can have a type of number or string depending upon how JavaScript interprets the input data. One can force a value to either a number or string by using the constrictor of Number or String. It is also possible to use other actions to force a variable or value to be either a string or number. Multiplying by 1 will force a value to be a number before any other operation.