These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

The value entered does not match the format of the field 'MSG'

J.alan
Registered: Jan 5 2011
Posts: 3
Answered

I am trying to do a simple calculation that involves division. It is my understanding that because it involves division I am getting the following error:
 
"The value entered does not match the format of the field [xxxxxx]"
 
Here is the calculation I'm trying to do:
 
field1/field2*100
 
Can anyone help me with a script that will stop this message from occurring?
 
Thanks in Advance
 
J. Alan

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You need to test that "field2" is not blank, not null and not zero.

Blank and null strings are treated as zero in arithmetic calculations.

What is the value of a number divided by zero?

If you are trying to compute a percentage, I recommend using the 'Percentage' format option.

You can change the format of the field to 'None' and observe the result.

George Kaiser

J.alan
Registered: Jan 5 2011
Posts: 3
@gkaiseril

I am trying to calculate a % but I don't want to set the format to 'Percentage' because the form already has a percentage sign, i.e., I would end up with two % if I use the 'Percentage' format.

That is why I am using the 'Number' format. I realize that I could set it to 'None' as well but I don't want to simply because that is not the desired affect. I don't want field3 to say 'Nan' when nothing is in field1 and/or field2 and I also want field three to have two numbers right of the decimal even if they are zero, i.e., xxx.00

So, again, what I am looking for is the script to Calculate: field1/field2*100 without the following error (even if field1 and/or field2 are blank):

"The value entered does not match the format of the field [xxxxxx]"

Anybodies help would be much appreciated.

Thanks,

J. Alan
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
Try this code as the custom calculation script for your field.

var field1 = this.getField("field1").value;
var field2 = this.getField("field2").value;
if (field1==null || field1=="" || field2==null || field2=="" || field2==0) {
event.value = "";
} else event.value = (field1/field2) * 100;

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

J.alan
Registered: Jan 5 2011
Posts: 3
@try67

You are the man (or woman). That worked perfectly. Thanks so much for your help.

Kindest Regards,

J. Alan
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
The values you can get are a nicely formatted percentage, NaN, Infinity, -Infinity, and a scientific notation number. All but the percentage result are text strings and can throw the error your are experiencing. Using the number format make further calculations more complex and subject to coding errors.

// temporary variable for result of calculation
var result = 0;
// perform division
result = this.getField('Text1').value / this.getField('Text2').value;
// set display switch
// check for result not being NaN
var bDisplay = !isNaN(result);
// check any variation of Infinity
bDisplay = (Math.abs(result) != "Infinity") & bDisplay;
// display result
if (bDisplay) {
event.value = result;
// AFPercent_Format(2,0); // optional format setting
} else {
// else display result
event.value = '';
// AFNumber_Format(2,0,0); // optional format setting
}



George Kaiser

curtismiller
Registered: Jun 3 2011
Posts: 1
try67 wrote:
Try this code as the custom calculation script for your field.var field1 = this.getField("field1").value;
var field2 = this.getField("field2").value;
if (field1==null || field1=="" || field2==null || field2=="" || field2==0) {
event.value = "";
} else event.value = (field1/field2) * 100;
Hey there

I just wanted to say thanks. Finding this meant that I still have hair left (i didn't end up pulling it all out)

Cheers

Curtis

AlexIAm
Registered: Nov 3 2011
Posts: 1
try67 wrote:
Try this code as the custom calculation script for your field.var field1 = this.getField("field1").value;
var field2 = this.getField("field2").value;
if (field1==null || field1=="" || field2==null || field2=="" || field2==0) {
event.value = "";
} else event.value = (field1/field2) * 100;
I could kiss you right now... this saved me so much frustration. Thanks!

-alex