# Populate different cells based on a calculation

New Here ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

Im new to using Adobe DC and API's so please bear with me .

Im looking for a way to populate differnet form fields based on calculation results.

If (Text18 - Text19 - Text20) > 0 then report on Text21

1. If (Text18 - Text19 - Text20) < 0 then report on Text22 and convert to number to absolute value

If (Text18 - Text19 - Text20) = 0 then report on Text21 & Text22

Please see reference below:

thank you for your time

TOPICS
How to, JavaScript, PDF forms

Views

150

Likes

Report

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

## 1 Correct Answer

Adobe Community Professional , Apr 13, 2021 Apr 13, 2021
Try this code as 'calculation' script of "Text22" field: var t18 = Number(this.getField("Text18").value); var t19 = Number(this.getField("Text19").value); var t20 = Number(this.getField("Text20").value); var t21 = this.getField("Text21"); var tot = t18-t19-t20; if(t18 == "" && t19 == "" && t20 == ""){ event.value = ""; t21.value = "";} else if(tot > 0){ event.value = ""; t21.value = tot;} else if(tot < 0){ event.value = Math.abs(tot); t21.value = "";} else if (tot == 0){ event.value = tot; t21.v...

Likes

3 Replies 3
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

Hi CMunro

Hope you are doing well and sorry for the trouble.

The workflow that you are trying to achieve is possible using the JavaScript. For more information please check out the help page: https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/js_developer_guide.pdf and see if that works for you.

Regards

Amal

Likes

Report

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

Copy link to clipboard

Copied

Try this code as 'calculation' script of "Text22" field:

var t18 = Number(this.getField("Text18").value);
var t19 = Number(this.getField("Text19").value);
var t20 = Number(this.getField("Text20").value);
var t21 = this.getField("Text21");
var tot = t18-t19-t20;
if(t18 == "" && t19 == "" && t20 == ""){
event.value = "";
t21.value = "";}
else if(tot > 0){
event.value = "";
t21.value = tot;}
else if(tot < 0){
event.value = Math.abs(tot);
t21.value = "";}
else if (tot == 0){
event.value = tot;
t21.value = tot;}

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

LATEST

Nesa, thank you very much for your help . The script you gave me worked like a charm!! 🙂

Likes

Report

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