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...

TransAct
Registered: Sep 13 2010
Posts: 3
Answered

Ok first of all, I am a new user and very new to acrobat. Pretty good at following instructions but am in the dark when it comes to javascript and writing formulas...

I developed a simple form for our sales team, looks much like a letter, allows our team to enter the customer name, address, city, state, zip and date at the top. In the middle of the letter it tabs down to fields that will require numbers to be entered and then several fields that will calculate
(i.e. average and percentage) using the numbers entered in the previous fields. I was able to figure out through internet research how to write a simplified field notation to handle the "average" calculation and "percentage" calculation, but there are the complete details of the form. It seems that no matter which field we type in, we get the message "the value entered....blah blah". HELP!

These are the fields that we enter values into:
Merchant Name, address, City, State, Zip, Attn, Date, Location

then tabs down to...
Current Monthly Volume
Total Transactions
First calculation is Average Ticket, which should be: Movolume/totaltrans

Current Monthly Cost
New Monthly Cost
Next calculation field is Monthly Savings, which should be: currentcost-newcost
Next calculation field is Cost Reduction %, which should be: 1.00-(newcost/currentcost)
Next caLculation field is 12 month reduction, which should be: savings*12
Next caLculation field is 48 month reduction, which should be: savings*48

My Product Information:
Acrobat Standard 9.3.1, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
The problem is likely due to the divisions that are taking place. Since they depend on field values, when certain field values are blank (or otherwise evaluate to zero) making the divisor zero, you get that error. The fix is to use code that deals correctly with the case of a divisor of zero.
TransAct
Registered: Sep 13 2010
Posts: 3
George thanks for the reply. Not sure i follow you completely but as I mentioned this is new to me.
As for your fix...think you could point me in the right direction with an example of the code to use? And where this code is entered? Again, I can follow directions well just need some guidance with the code writing and the basics. Thanks.


George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
The first field that you show a division is the "Average Ticket". If you use the following JavaScript in this field's Calculate event, it should fix the problem for that field. You'd have to do something similar for any other field that performs a division where the demoninator is based on a field value that could evaluate to zero.

// Custom calculation script(function () { // Get field values as numbersvar v1 = +getField("Movolume").value;var v2 = +getField("totaltrans").value; // Perform calculation if denominator is not zero (or blank)event.value = (v2 !== 0) ? (v1 / v2) : ""; })();
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
The next field that includes a division is "Cost Reduction %". Here's the code for that, using an "if" statement, which may make it more clear:

// Custom calculation script(function () { // Get field values as numbersvar v1 = +getField("newcost").value;var v2 = +getField("currentcost").value; // Perform calculation if denominator is not zero (or blank)if (v2 !== 0) {event.value = 1 - v1/v2;} else {event.value = "";} })();
TransAct
Registered: Sep 13 2010
Posts: 3
Thanks George!!!!! Those codes worked great and now the form is functional. Appreciate the help. You rock!
AnnM
Registered: Nov 12 2010
Posts: 2
I'm having the same situation and understand the divide by 0 problem, but am not able to translate the code provided to match the fields in my form.

I have:
3 rows (Fund Types) of 4 columns (Cost categories) to add down and across for Total Cost Categories and Total Fund Type.
The fields start blank and may not all be filled in.

The percent of each Cost Category must be calculated.





AnnM

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
AnnM,

If you'd like someone to suggest specific code, it would help to know the details, the field names involved in particular.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Ann,

Have you been able to do this in Excel?

Without field names or a form example, it is difficult to provide the code.

After you get the fields created for the columns and rows, the fields for the totals of the rows and columns, and the grand total, you can create fields for the percentages for the rows and columns. The divisor for each row or column percentage will be the grand total, the dividend will be the total for the row or column.

You could use a custom calculation script like and change the dividend :

// Custom calculation script
// field name for dividend and divisor
var cDividend = "Cost.Total.0"; // name for the total for row or column field - the dividend
var cDivisor = "Amount.Total"; // name for the grand total for rows and columns - the divisor
// do not change any code below this comment
// Get field values as numbers
var nDividend = Number(this.getField(cDividend).value);
var nDivisor = Number(this.getField(cDivisor).value);
(function () {
// Perform calculation if denominator is not zero (or blank)
if (nDivisor !== 0) {event.value = nDividend / nDivisor;}
else {event.value = "";} })();

You could even use a document level function to perform the division and you would only need to provide the value for the dividend and divisor.

Document level funciton:

function Division (nDividend, nDivisor) {
// force parameters to numbers
nDividend = Number(nDividend);
nDivisor = Number(nDivisor);
var nResult = "";
// Perform calculation if denominator is not zero (or blank)
if (nDivisor !== 0) {nResult = nDividend / nDivisor;}
return nResult;
}

The custom calculation script for the field then becomes:

// Custom calculation script
// field name for dividend and divisor
var cDividend = "Cost.Total.0"; // name for the total for row or colum
var cDivisor = "Amount.Total"; // name for the grand total for rows and colums
// do not change any code below this comment
event.value = Division(this.getField(cDividend).value, this.getField(cDivisor).value);


Sample Allocationhttps://acrobat.com/#d=Hy6R-oFOEyl5jx5r*2jLjw

George Kaiser

AnnM
Registered: Nov 12 2010
Posts: 2
George_Johnson wrote:
The first field that you show a division is the "Average Ticket". If you use the following JavaScript in this field's Calculate event, it should fix the problem for that field. You'd have to do something similar for any other field that performs a division where the demoninator is based on a field value that could evaluate to zero.
// Custom calculation script(function () { // Get field values as numbersvar v1 = +getField("Movolume").value;var v2 = +getField("totaltrans").value; // Perform calculation if denominator is not zero (or blank)event.value = (v2 !== 0) ? (v1 / v2) : ""; })();

AnnM

KFreeman
Registered: Jan 21 2008
Posts: 4
I'm new to Acrobat X Pro, upgrading recently from 8 Pro. I'm working on a form where I have everything set, including calculations, except for three fields which need a more complex calculation. I need to show Recordable Injuries multiplied by 200000, then divided by Hrs Worked to obtain the Recordable Incident Rate. The multiplier (200000) is not stored in the form as a field. I have tried using the simplified field notation for the calculation, and the custom calculation script, although I obviously don't understand it at this point. The error I get is that the "value entered does not match the format of the field ...". I appreciate any help you can give me on this. Thank you!

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Since you will have a divisor, Hrs Worked, that can be zero or null you can not use the simplified field notation.

Have you tried setting the field for the calculation to a format of "None"?

You need to control the program statement execution by the use of the 'if' statement to test for a zero or null and then branch around that block of code. The simplified field notation entry does not allow for this type of program statement.

You can only use a custom JavaScript calculation to perform this calculation.

// custom calculation script for Recordable Incident Rate;
// variables for needed field names;
var cRecordableInjuries = "Recordable Injuries";
var cHoursWorked = "Hrs Worked";
// define variable for the multiplier;
var nMultiplier = 200000;
// get the values of the needed fields;
var nHoursWorked = this.getField(cHoursWorked).value;
var nRecordableInjuries = this.getField(cRecordableInjuries).value;

// test for numeric input values
if(isNaN(nHoursWorked)) {
app.alert("Numeric Entry Required\n\nNumber of hours worked must be a numeric value", 1, 0);
} // end not a number for hours worked

if(isNaN(nRecordableInjuries)) {
if(app.viewerVersion < 6) {
app.alert("Numeric Entry Required\n\nRecordable Injuries must be a numeric } // end not a number for recordable injuries;

// adjust Recordable Injuries by multiplier
nRecordableInjuries *= nMultiplier;

// default value of Recordable Incident Rate;
// null result if no calculation performed;
event.value = "";
// compute incident rate if hours worked is not equal to zero;
if(nHoursWorked != 0 & !isNaN(nHoursWorked) & !isNaN(nRecordableInjuries)) {
event.value = nRecordableInjuries / nHoursWorked;
} // end of computation;
// end of custom calculation script;

There should be no difference in the calculation script from version 8 to X. The provided calculation will work with any version of Acrobat.

George Kaiser

KFreeman
Registered: Jan 21 2008
Posts: 4
Thank you, George. I tried copying the information you provided, as well as typing it in, and seem to get a Syntax Error: unterminated string literal 18: at line 19. I'm not sure what I am missing. Hoping you can help me once again.

KFreeman
Registered: Jan 21 2008
Posts: 4
George, I have tried using the information you sent, and get an error message. I am wondering what needs to be changed with the following lines of code:

if(isNaN(nRecordableInjuries)) {
if(app.viewerVersion < 6) {
app.alert("Numeric Entry Required\n\nRecordable Injuries must be a numeric } // end not a number for recordable injuries;

After looking at it for a bit, I noticed that there are two left curly braces and only one right. Also, the third line of that section shows (" but there isn't a ") to end it.

I have tried every variation I can think of, but haven't found the right one yet. Can you please take a look and point me in the right direction?

Thank you!
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
The lines that read:

if(isNaN(nRecordableInjuries)) {
if(app.viewerVersion < 6) {
app.alert("Numeric Entry Required\n\nRecordable Injuries must be a numeric } // end not a number for recordable injuries;


Should be:

if(isNaN(nRecordableInjuries)) {
app.alert("Numeric Entry Required\n\nRecordable Injuries must be a numeric", 1, 0)
}
// end not a number for recordable injuries;

George Kaiser

KFreeman
Registered: Jan 21 2008
Posts: 4
Thank you!! That fixed the issue!! I appreciate all your help and guidance.
pipdicker
Registered: Nov 4 2011
Posts: 2
I am having trouble with a form in which I am calculating a simple discount for three columns of offers within a table.

The error code I receive is "the value entered does not match the format of the field".

Below is my formula:

var a =this.getField("Offer 1 Promo");
var b =this.getField("Offer 1 Retail");
event.value=(a.value/b.value)

I believe it is because the "Offer Columns" are dividing by zero. How do I correct this?
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You need to use an "if" statement to test that the value of b is not zero and if that is true then perform the division.

// custom calculation script:
event.value = ""; // clear the field value
var a = this.getField("Offer 1 Promo");
var b = this.getField("Offer 1 Retail");
// test for non- zero value
if(b.value != 0) {
// non-zero divisor - preform calculation
event.value=(a.value/b.value)
} // end if not zero not null

Since you are repeating this type of code repeatedly, I would look at using a document level JavaScript function to take the 2 values as input parameters and return the result of the division.

function Division(nDividend, nDivisor) {
var nResult = "";
if(nDivisor != 0) {
nResult = nDividend / nDivisor;
}
return nResult;
} // end Division function

Then the custom calculation for a field becomes:

var a = this.getField("Offer 1 Promo");
var b = this.getField("Offer 1 Retail");

event.value = Division(a.value, b.value);


It is even possible to create a string for field names so one could even use a calculation like:

// row for computation
var nRow = 1; // change for row number
// compute name of fields
var cPromo = "Offer " + nRow + " Promo";
var cRetail = "Offer " + nRow + "Retail";
// get field objects
var a = this.getField(cPromo);
var b = this.getField(cRetail);
// preform the calculation
event.value = Division(a.value, b.value);


George Kaiser

pipdicker
Registered: Nov 4 2011
Posts: 2
Thanks so much George.