• Global community
• Language:
• Deutsch
• English
• EspaÃ±ol
• FranÃ§ais
• PortuguÃªs
• æ—¥æœ¬èªžã‚³ãƒŸãƒ¥ãƒ‹ãƒ†ã‚£
Dedicated community for Japanese speakers
• í•œêµ­ ì»¤ë®¤ë‹ˆí‹°
Dedicated community for Korean speakers
Exit
• Re: Using Radio Button Selections to Calculate Bon...

# Using Radio Button Selections to Calculate Bonus

New Here ,
May 17, 2019 May 17, 2019

Copy link to clipboard

Copied

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!

TOPICS
Acrobat SDK and JavaScript

Views

455

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

## 1 Correct answer

Community Expert , May 19, 2019 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.

4 Replies 4
Community Expert ,
May 17, 2019 May 17, 2019

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

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 Expert ,
May 19, 2019 May 19, 2019

Copy link to clipboard

Copied

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.

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 Expert ,
May 19, 2019 May 19, 2019

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
May 20, 2019 May 20, 2019

Copy link to clipboard

Copied

LATEST

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