Skip to main content
Participant
January 15, 2024
Answered

What I thought was simple division between two fields is not working

  • January 15, 2024
  • 1 reply
  • 1217 views

I am hopeless with the abstract e.g. programming.

Using Acrobat Forms I wish to divide one text field into another. One field is a result of a calculation of user entries, the other will be a number entered by the user. 

Reading posts I see this cannot be done by simple field notation  (Text 7)/Text 11. I tried several variations.

Reading the not so simple calculations help page I arrived at the following formula in my target field (Text12) which I think is close but not quite correct.

event.value = ( this.getField("Text7"). value/ this.getField("Text11")).value;

but this does not work. A value remains in the target field Text12 from previous attemps but does not change and is also incorrect if I calculate longhand.

Any assistance greatly appreciated.

This is not confidential so happy to post the whole thing; it's to help plumbers calculate a flow rate and pipesize.

Correct answer Nesa Nurani

You can use this script:

var t7 = Number(this.getField("Text7").valueAsString);
var t11 = Number(this.getField("Text11").valueAsString);
if(t11 === 0)
event.value = "";
else
event.value = t7/t11;

If it doesn't calculate correctly, you need to change field calculation order by selecting 'Prepare form' tool, clicking on 'More' and then 'Set field calculation order', fields that calculate first should be on top.

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
January 15, 2024

You can use this script:

var t7 = Number(this.getField("Text7").valueAsString);
var t11 = Number(this.getField("Text11").valueAsString);
if(t11 === 0)
event.value = "";
else
event.value = t7/t11;

If it doesn't calculate correctly, you need to change field calculation order by selecting 'Prepare form' tool, clicking on 'More' and then 'Set field calculation order', fields that calculate first should be on top.

Participant
January 16, 2024

Thank you so much. I would not have been able to have arrived at that script ever. Again, thank you, works like a dream.