Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
15

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

New Here ,
Jan 15, 2024 Jan 15, 2024

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.

TOPICS
JavaScript , PDF forms
1.2K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Jan 15, 2024 Jan 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.

View solution in original post

Translate
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
Community Expert ,
Jan 15, 2024 Jan 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.

Translate
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
New Here ,
Jan 16, 2024 Jan 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.

Translate
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
New Here ,
Apr 10, 2025 Apr 10, 2025
LATEST

Thank you! I've never worked with Java before, but this made perfect sense and really helped. 

Translate
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