8 Replies Latest reply on Sep 21, 2012 11:01 AM by George_Johnson

# Value Entered Does Not Match the Format of the Field

Hi,

I am new to JavaScript and development of PDFs with JavaScript.  I have done some research on this error and understand why it is generated.  Currently I'm trying to create a PDF with some basic calculations in it that require division.  I have the fields all formatted to numbers to represent currency.  I am using the simplified field notation calculations to generate my results, and I understand if I remove the number format from the fields then I won't get the "The value entered does not match the format of the field [ field box ]"

I would prefer not to remove the format features, because these values need to be represented as dollar amounts.  Can someone please help with or direct me to a solution of putting together a simple custom script calculation?  Or provide another solution for my problem.  Any help is greatly appreciated. Below is an example of the calculation I'm trying to perform.

Box1   Box2   Box3  Box4  Box5  Box6

Box1 / Box2 = Box3

Box4 / Box3 = Box5

Box2 - Box5 = Box6

Box1, Box2, and Box4 are known values.  Box3, Box5, and Box 6 are calculated

So if

Box1 = \$40,000.00

Box2 = \$600.00

Box4 = \$20,000.00

Then

\$40,000 / \$600.00 = Box3 66.6666

\$20,000 / 66.6666 = Box5 \$300.00

\$600.00 - \$300.00 = Box6 \$300.00

• ###### 1. Re: Value Entered Does Not Match the Format of the Field

If the calculation involves division by zero, what do you want the field value to be set to? A field is commonly set to blank when this happens, but you have a choice.

• ###### 2. Re: Value Entered Does Not Match the Format of the Field

If I understand your question you're asking what default value I would like the field to be set to?  I would prefer it to be zero or blank until the values are inputted in from the data that is collect, simply to avoid confusion.  The format of the fields I would like to be set to numbers to represent currency, and from my experience this seems to be what cause the error because its trying to divide a number by zero.  I'm hoping that a JavaScript would solve some of my issues.  I don't know how to write the script, or certain that it will work.   If I have to have a value there so I don't get prompted with an error every time I use the form then I guess 1 would be a sufficient value to you.  Please excuse me if I didn't understand what you are asking I'm new to developing PDF forms.

• ###### 3. Re: Value Entered Does Not Match the Format of the Field

No, that's what I was after. The following can be used as the custom calculate script for Box3, and you'd do much the same for the other fields:

// Custom Calculate script for Box3

(function () {

// Get the field values, as numbers

var numerator = +getField("Box1").value;

var denominator = +getField("Box2").value;

// Perform the calculation if the denominator doesn't evaluate to zero

if (denominator !== 0) {

event.value = numerator / denominator;

} else {

event.value = "";  // blank

}

})();

This can be simplified to just:

// Custom Calculate script for Box3

(function () {

var v1 = +getField("Box1").value;

var v2 = +getField("Box2").value;

event.value = v2 !== 0 ? v1 / v2 : "";

})();

• ###### 4. Re: Value Entered Does Not Match the Format of the Field

Hey George,

I really appreciate your help.  The script works great, and does exactly what I need it to.  I did run into one more issue, and that involves the last portion of the calculation in box 6.  I was using simplified field notation to calculate;

Box2 - Box5 = Box6

Now that I'm using the script you have provided for me the last calculation will not execute.  I'm not sure why it won't perform the last calculation  I'm guessing its because I'm trying to perform a script in two other boxes, and simplified field notation in the other.  So I'm thinking I'll need a subtraction script to get that last boxes to yield the results of the calculation.  I'll hunt around on the web to see if I can find a subtraction script.  Again I appreciate all your help.

• ###### 5. Re: Value Entered Does Not Match the Format of the Field

That's probably not it. Check the JavaScript console (Ctrl+J) for any errors and make sure the field calculation order is correct. Exactly how you do that depnds on which versio of Acrobat you're using.

• ###### 6. Re: Value Entered Does Not Match the Format of the Field

Thanks again George.

You are correct the field calculation order wasn't right.  Everything works like a charm!

• ###### 7. Re: Value Entered Does Not Match the Format of the Field

Hi George,

I have another question for you.  I have a column that is titled "City"  Intitally I wanted to be able to enter in the name of the city into one field and it auto populate the other fields with the same name.  Since I'm new to PDF forms I thought I would just copy and paste the same field multiple times so once I enter in the name in the first field it would fill in the rest of the fields with the same name.  This works, but in some cases I need one or two of the fields to be different and allow me to edit the name.  As you can expect every time I edit one field it changes the name for all the fields.  So my question is; Is there a way to have the column auto populate the same name that enter in the first field, but allow me to change the fields below if I need to?

Here is a rough idea of what I'm trying to do

City

CityRow1

CityRow2

CityRow3

CityRow4

City

CityRow1 - Kansas City

CityRow1 - Kansas City

CityRow1 - Kansas City

CityRow1 - Kansas City

I would like the form to initially auto populate the city to save time, but if I have an instance where its in a different city I need to be able to change the value of only that particular field.

City

CityRow1 - Kansas City

CityRow2 - Kansas City

CityRow3 - Lawrence

CityRow4 - Kansas City

Again I appreciate all you help thus for. Thanks again!

• ###### 8. Re: Value Entered Does Not Match the Format of the Field

There are a number of ways to do this, but before we proceed, consider the following scenario:

1. The user enters a city in the first row, which causes it to autopopulate the other rows.

2. The user then changes the city in one or more of the other rows.

3. The user then goes back and changes the city in the first row.

After step 3, should the city in any of the other rows get automatically changed, or do you only want the city fields to be automatically populated if they're blank?