Skip to main content
Participant
April 30, 2020
Question

Need help preparing form with division calculations

  • April 30, 2020
  • 3 replies
  • 1301 views

I have been trying to prepare a form with multiple rows and columns.  One row has 6 text boxes.  Each text box needs to divide the raw data (of that specific text box only) by 3 (ie. if I input 1, I need the box to display 0.333).  I have tried to use the simplified field notation to do this. It works fine when I enter data into the first box.  The problem is that once I enter data into the second text box, it further divides the first text box data (ie the first text box goes from 0.333 to 0.111).  How do I make these boxes only divide by 3 without being associated with each other?

 

Thanks in advance.

This topic has been closed for replies.

3 replies

JR Boulay
Community Expert
Community Expert
April 30, 2020

Hi Thom, great minds thinks alike!

😉

Acrobate du PDF, InDesigner et Photoshopographe
JR Boulay
Community Expert
Community Expert
April 30, 2020

Place this script as a Validation script (not a Calculation script):

if (event.value != 0) {event.value = event.value / 3;}

 

A Calculation script is triggered whenever any field in the document goes through the "onBlur" state.
A Validation script is only triggered when the value of the field concerned is modified.

Acrobate du PDF, InDesigner et Photoshopographe
Chris5730Author
Participant
April 30, 2020

Awesome! Thank you!

Thom Parker
Community Expert
Community Expert
April 30, 2020

So you have created input boxes that divide themselves?  Think about it. The calculation is dividing the current value of the text box by 3. So, each time calculations are called, the same divide contents by 3 calculation is called. So of course it's divided again.

 

The boxes are not associated with each other. The calculation script is called each time any value on the form is changed. That's how they work.

 

Write the calculation in JavaScript and put it in the Custom Validation script. This will work.  However, it's still a bad solution. What is it that you are trying to do? Perhaps there is a better way to go about it than having a field operate on itself. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Chris5730Author
Participant
April 30, 2020

 

Here is a snapshot of a row.  My raw data is 0-3, and I am just trying to display each box in decimal format (to the 3rd decimal place).  There are actually 3 rows throughout the form that have this decimal conversion, and they are all linked.