Skip to main content
Participant
May 17, 2019
Answered

Using Radio Button Selections to Calculate Bonus

  • May 17, 2019
  • 3 replies
  • 687 views

I've been tasked to create a simple form to help sales reps in our company calculate their bonus. I am a creative person, but not a coding/technical person, so I have this cool idea in my head but I don't know how to make it work. I've scoured the internet and forums and have found some helpful threads but can't seem to find what I'm looking for. So here's what I'm trying to do:

Our sales reps have 4 targets that they need to hit (ex./ "category 1," "category 2," etc...) Depending on how many of those targets they achieve, their bonus can increase.

- Example:/ If a sales rep sells 10 units and only hits 1 target category, then their sales are multiplied by $10. If another sales rep also sells 10 units, but hits 2 target categories, then their sales are multiplied by $20. 3 targets = multiply by $30, and all 4 targets = multiply by $40.

The way my form is set up is I have a field for the quantity of units sold, where they simply input a number. I then have 4 groups of (yes/no) radio buttons for them to select whether or not they hit their target in each category. Depending on the number of 'yes' selections will determine what number to multiply the total units sold by.

I don't know if it's easier to use  if/else statements or maybe it would be easier to sum the number of 'yes' selections and then determine what to multiply by?

I hope this makes sense, and any help is greatly appreciated! Thank you!

This topic has been closed for replies.
Correct answer try67

You don't need any code to do it, actually, if you set it up correctly.

Just set the "Radio button choice" value of the Yes fields as 1 and of the No fields as 0, and then you could use the built-in Sum function under the calculate tab of your total text field to sum them up directly.

3 replies

Participant
May 20, 2019

Thank you both! try67​ that was easy enough and worked for what I needed. I thought it would be way more complicated than that.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 19, 2019

You don't need any code to do it, actually, if you set it up correctly.

Just set the "Radio button choice" value of the Yes fields as 1 and of the No fields as 0, and then you could use the built-in Sum function under the calculate tab of your total text field to sum them up directly.

Thom Parker
Community Expert
Community Expert
May 19, 2019

True, I was going to mention that, but without more information it's hard to know what they want. Better to have a generic solution that handles no choice.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Thom Parker
Community Expert
Community Expert
May 17, 2019

Summing radio buttons is the way to go. Especially if they are grouped by naming them with the "dot" notation.  However, you will still need a conditional to determine what to add in the sum.

here's a code snippet, assuming the Yes button has an export of "Yes".

sum += (this.getField(RadioName).value == "Yes")?1:0;

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often