Skip to main content
Participant
October 17, 2023
Question

need help with javascript for form calculations

  • October 17, 2023
  • 3 replies
  • 1742 views

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

This topic has been closed for replies.

3 replies

try67
Community Expert
Community Expert
October 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 = "";
]
Participant
October 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")?  

Bernd Alheit
Community Expert
Community Expert
October 21, 2023

Try the forum for Adobe Acrobat.

Bernd Alheit
Community Expert
Community Expert
October 19, 2023

Try the forum for Adobe Acrobat.

Participant
October 19, 2023

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