Pdf Custom Calculation script

New Here ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

Hi Hope you can help - giving probably way to much detail here:

I am getting "the value entered does not match the format of the field [text1]

I changed the format of  all fields to 0 decimal points because I am trying to calcualte sheet count ( whole numbers) needed for print production:

F1 is record count

F2 is # of pages

F3 is simplex or duplex

F4 is imposition

I have to multiply the Record count * number of pages * (1 simplex) or (2 duplex) then divide the imposition to get the total sheets needed for production  ex:  10 records x 4 pages = 40 x simplex = 40 / imposition lets say "2" = 20 sheets of paper to complete the job.

I think I have this covered in my calculation below, except the error is at F4. I do not know how to clear it.

 

var f1 = this.getField("calc1A").value;
var f2 = this.getField("calc1B").value;
var f3 = this.getField("calc1C").value;
var f4 = this.getField("calc1D").value;
if (f2&&f3&&f4==0) event.value=0;
var f5=f1*f2*f3;
event.value= f5/f4;

TOPICS
JavaScript

Views

91

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Most Valuable Participant , Apr 02, 2021 Apr 02, 2021
Replace this part of the code:     if (f2&&f3&&f4==0) event.value=0; var f5=f1*f2*f3; event.value= f5/f4;     With this:     if (f4==0) event.value=""; // I changed it because zero is NOT the correct result. It should be nothing at all, as division by zero is not allowed. else { var f5=f1*f2*f3; event.value= f5/f4; }  

Likes

translate

Translate

Translate
Most Valuable Participant ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

Replace this part of the code:

 

 

if (f2&&f3&&f4==0) event.value=0;
var f5=f1*f2*f3;
event.value= f5/f4;

 

 

With this:

 

 

if (f4==0) event.value=""; // I changed it because zero is NOT the correct result. It should be nothing at all, as division by zero is not allowed.
else {
var f5=f1*f2*f3;
event.value= f5/f4;
}

 

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

Just a tip, if you want to use f2,f3 and f4 when comparing them you need to change

this: (f2&&f3&&f4==0)

to this: (f2==0&&f3==0&&f4==0)

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

In this case you probably want to use OR, not AND, and also this is not needed at all, since if f1 or f2 or f3 are zero the result will be zero anyway. It's only f4's value that needs to be tested in this way.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines