Help with converting an excel formula into Javascript

Community Beginner ,
Jul 30, 2019

Copy link to clipboard

Copied

I am trying to convert an Excel expression/formcalc script that essentially divides the totals of two fields provided on a PDF form. One field may include a total entered on a another page.  The formcalc script I am currently using works, and is listed below.  Is there any chance someone might be able to help me with converting to javascript?  Thanks so much!

if(Page1.Total_undupl ne 0 & HasValue(Page1.Total_undupl)) then

Total_al_instr / Page1.Total_undupl

else

null

endif

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You can use something like this:

var v1 = Number(this.getField("Total_al_instr").valueAsString);

var v2 = Number(this.getField("Page1.Total_undupl").valueAsString);

if (v2==0) event.value = "";

else event.value = v1/v2;

TOPICS
Acrobat SDK and JavaScript, Windows

Views

147

Likes

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

Help with converting an excel formula into Javascript

Community Beginner ,
Jul 30, 2019

Copy link to clipboard

Copied

I am trying to convert an Excel expression/formcalc script that essentially divides the totals of two fields provided on a PDF form. One field may include a total entered on a another page.  The formcalc script I am currently using works, and is listed below.  Is there any chance someone might be able to help me with converting to javascript?  Thanks so much!

if(Page1.Total_undupl ne 0 & HasValue(Page1.Total_undupl)) then

Total_al_instr / Page1.Total_undupl

else

null

endif

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You can use something like this:

var v1 = Number(this.getField("Total_al_instr").valueAsString);

var v2 = Number(this.getField("Page1.Total_undupl").valueAsString);

if (v2==0) event.value = "";

else event.value = v1/v2;

TOPICS
Acrobat SDK and JavaScript, Windows

Views

148

Likes

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
Jul 30, 2019 0
Most Valuable Participant ,
Jul 30, 2019

Copy link to clipboard

Copied

You can use something like this:

var v1 = Number(this.getField("Total_al_instr").valueAsString);

var v2 = Number(this.getField("Page1.Total_undupl").valueAsString);

if (v2==0) event.value = "";

else event.value = v1/v2;

Likes

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
Reply
Loading...
Jul 30, 2019 0
Community Beginner ,
Jul 30, 2019

Copy link to clipboard

Copied

Thank so so much! Appreciate your help.

Likes

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
Reply
Loading...
Jul 30, 2019 0