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

need help with javascript for form calculations

Community Beginner ,
Oct 17, 2023 Oct 17, 2023

I use Adobe Acrobat to create pretty straight-forward fillable forms for my company often.  However, I have a new order form I am creating and the only sticking point I have is trying to figure out how to get two different  fields to do a calculation ONLY IF a specific button field is turned on.

 

I have the form totalling up the rows I need to get a NET TOTAL for all the pertaining rows, so I have that set. That is simple and will be the majority of the orders.  But I also have a field just above that that is for 15% COMMISSION, then a GROSS TOTAL field is above that field.  I only need the last two fields to populate if a certain button is clicked on the form.  For this order form the majority of the time the orders are a simple NET total, so I have a button group at the top of the form... one is "NET" one is "GROSS".  I have the "Net" button as the default.  But if 15% commission needs to be subtracted from the gross total, the user is to click the "Gross" button.  I need that action to put different totals in the fields. If the "Net" button at the top is clicked (as is the default) I ONLY want the total of rows to show in the NET TOTAL field, and the other 2 to stay blank. 

 

How in the world do I get this to happen?  I am not very well-versed in Javascript so I believe I need some custom scripts to make these actions.  HELP!!!  If you need some screen shots to get it better let me know.

 

Thanks in advance,

Wendy

TOPICS
How to
1.3K
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 ,
Oct 19, 2023 Oct 19, 2023

Try the forum for Adobe Acrobat.

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 Beginner ,
Oct 19, 2023 Oct 19, 2023

ok thanks.  I thought I was in the right place... but I'll post there.

 

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 ,
Oct 20, 2023 Oct 20, 2023

Try the forum for Adobe Acrobat.

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 ,
Oct 23, 2023 Oct 23, 2023

For all of your calculated fields you need to use something like this as their custom calculation code:

if (this.getField("NetGross").valueAsString=="Net") {
	// perform calculation for "Net" option
} else if (this.getField("NetGross").valueAsString=="Gross") {
	// perform calculation for "Gross" option
} else {
	// perform calculation for neither option, probably want to keep the field empty.
	event.value = "";
]
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 Beginner ,
Oct 23, 2023 Oct 23, 2023

Thanks for your response.  So would I put those calculations in my totals fields?  Do I have to do anything up at the buttons (one is "Gross" the other is "Net")?  

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 Beginner ,
Oct 25, 2023 Oct 25, 2023

Hi try67...  I tried adding your JavaScript calculation code above into my form and it's giving me a Syntax error.   See attached screenshot.

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 ,
Oct 25, 2023 Oct 25, 2023
LATEST

You have nothing after 'else{' you need to add script or remove else part if you don't need it.

Also, you don't have any calculation in your script, script from try67 was just an example, you need to add calculations where it says:

// perform calculation for "Net" option

 

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