Highlighted

Help with Java Script w division when both numbers are 0 until user input

Community Beginner ,
Oct 19, 2020

Copy link to clipboard

Copied

Hello I am a beginning to both Adobe and Java.  

I am trying to do the division of two fields = S5totalotherrev / S5MealequivalentRate

However, both fields are blank until the user enters data, which I discovered returns an error.  So after reading some of the others posts, I wrote the following script: (note I'm only doign the check on S5MealequivalentRate because the data isn't entered until later in the form and I didn't know how to write it to check both)

 

Var nRate = this.getField(“S5MealequivalentRate”).value;

If(nRate !=0){event.value = this.getField(“S5totalotherrev”).value / nRate;} else {event.value = “”;}

 

I'm getting a syntax error and since I basically have no clue when it comes to Java I don't know what I did wrong.  

 

Can someone help me with this script?

 

Thanks

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

Use the character ", not “

Use var, not Var

Use if, not If

Info: Acrobat uses Javascript, not Java

TOPICS
PDF forms

Views

53

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 Java Script w division when both numbers are 0 until user input

Community Beginner ,
Oct 19, 2020

Copy link to clipboard

Copied

Hello I am a beginning to both Adobe and Java.  

I am trying to do the division of two fields = S5totalotherrev / S5MealequivalentRate

However, both fields are blank until the user enters data, which I discovered returns an error.  So after reading some of the others posts, I wrote the following script: (note I'm only doign the check on S5MealequivalentRate because the data isn't entered until later in the form and I didn't know how to write it to check both)

 

Var nRate = this.getField(“S5MealequivalentRate”).value;

If(nRate !=0){event.value = this.getField(“S5totalotherrev”).value / nRate;} else {event.value = “”;}

 

I'm getting a syntax error and since I basically have no clue when it comes to Java I don't know what I did wrong.  

 

Can someone help me with this script?

 

Thanks

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

Use the character ", not “

Use var, not Var

Use if, not If

Info: Acrobat uses Javascript, not Java

TOPICS
PDF forms

Views

54

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
Oct 19, 2020 0
Adobe Community Professional ,
Oct 19, 2020

Copy link to clipboard

Copied

Use the character ", not “

Use var, not Var

Use if, not If

Info: Acrobat uses Javascript, not Java

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...
Oct 19, 2020 1
Community Beginner ,
Oct 19, 2020

Copy link to clipboard

Copied

Okay I switched it, but I'm still getting an error.  

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...
Oct 19, 2020 0
Engaged ,
Oct 19, 2020

Copy link to clipboard

Copied

You probably didn't fix all errors.

var nRate = this.getField("S5MealequivalentRate").value;

if(nRate !=0){event.value = this.getField("S5totalotherrev").value / nRate;} else {event.value = "";}

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...
Oct 19, 2020 1
Community Beginner ,
Oct 19, 2020

Copy link to clipboard

Copied

Thank you.  That worked.  This is so confusing when you don't understand it.

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...
Oct 19, 2020 0