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

Javascript formula Not Working

Community Beginner ,
Aug 09, 2020 Aug 09, 2020

Copy link to clipboard

Copied

Total nubie here with no knowledge of javascript yet.  I have one last item I need to complete a form I am working on.   I need to take the amounts of two fields and check it against a drop down menu of Yes or No to determine if the items should be taxed 6%.   The formula someone provided to me didn't work.  It was:

var a = this.getField("Item3_Amt").value; var b = this.getField("Item4Amt").value; var c = this.getField("Dropdown").value; if(c == "No"){event.value = "$0.00"; }else event.value = (a+b)*0.6;

 

Unfortunately it doesn't work.   Can anyone tell me what the problem might be?

Also, after looking at the form a bit more I think it would work better to replace the dropdown with a check box.  So what would a working formula look like with a checkbox instead of the dropdown.

For you guys with the knowledge, your awesome!  Thanks

TOPICS
Acrobat SDK and JavaScript

Views

624

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
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 13, 2020 Aug 13, 2020

Remove the $

Votes

Translate

Translate
Community Expert ,
Aug 09, 2020 Aug 09, 2020

Copy link to clipboard

Copied

+++EDITED REPLY  , FIXED AN ERROR IN THE LAST LINE OF THE SCRIPT

 

Just place the script in the custom calculation script section of the field that will be performing the check. 

 

Like this:

 

 

var a = this.getField("Item3_Amt").value; 
var b = this.getField("Item4_Amt").value; 
var c = this.getField("Dropdown36").valueAsString;

 if(c == "yes") event.value = (a+b)*0.06;
else event.value = 0;


 

 

 

Note that 6%  is not calculated with 0.6.

 

Also, all you need to do to have the empty calculated field display "$0.00" is use the built-in fomat scheam for your numbers.

 

See slide below:

 

format number.png

Votes

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
community guidelines
Community Expert ,
Aug 09, 2020 Aug 09, 2020

Copy link to clipboard

Copied

You didn't have to open new post, you could just ask in your first thread what the problem was with the code and I would gladly help you, also in my code there is *.06 and not *0.6

Votes

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
community guidelines
Community Beginner ,
Aug 09, 2020 Aug 09, 2020

Copy link to clipboard

Copied

I apologize for the duplication.  
Could you tell me what this formula would look like substituting a check box for the drop down?

Votes

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
community guidelines
Community Expert ,
Aug 09, 2020 Aug 09, 2020

Copy link to clipboard

Copied

That is a  different question tad_boomer.

 

As mentioned by Nesa you should ask in the original thread.

 

Also consider opening a new thread since now you want to throw a checkbox in the mix.

 

Are you looking into learning JavaScript or are you asking for someone to write the code for you?

 

Votes

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
community guidelines
Community Expert ,
Aug 09, 2020 Aug 09, 2020

Copy link to clipboard

Copied

Maybe is a duplicated post.

 

Votes

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
community guidelines
Community Expert ,
Aug 09, 2020 Aug 09, 2020

Copy link to clipboard

Copied

I'm assuming that you want if checkbox is checked tax is calculated?

use this code:

var a = this.getField("Amount3").value;
var b = this.getField("Amount4").value;
var c = this.getField("Enter Checkbox Field Name Here");
if(c.isBoxChecked(0)){event.value = (a+b)*.06;
}else event.value = "$0.00";

 

Also consider formating your field to number and add currency simbol ( as ls_rbls mention in this post and try67 in your first post) in that case replace "$0.00" with "0"

Votes

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
community guidelines
Community Beginner ,
Aug 13, 2020 Aug 13, 2020

Copy link to clipboard

Copied

Hello Everyone.

I was unable to get any of the scripts to work and then the client I was making the form for decided they wanted some changes which required me to start from scratch again.  But I am back to the same problem with this formula.  This is what I put in:
var a = this.getField("Amount3").value;
var b = this.getField("Amount4").value;
var c = this.getField("Item7");
if(c.isBoxChecked(0)){event.value = (a+b)*.06;
}else event.value = "$0.00";

The formula works but when you go to put the amounts in Amount3 and Amount4 Acrobat flashes a message "The value entered does not match the format of the field (Amount7)  

Votes

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
community guidelines
Community Expert ,
Aug 13, 2020 Aug 13, 2020

Copy link to clipboard

Copied

Remove the $

Votes

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
community guidelines
Community Beginner ,
Aug 14, 2020 Aug 14, 2020

Copy link to clipboard

Copied

LATEST

Thank you.  It works perfectly now.  

Votes

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
community guidelines