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

Calculate Percentage Based on Radio Button Selected

New Here ,
Oct 19, 2023 Oct 19, 2023

Hello Good People! 🙂
Forwarning you that I have no experience with scripts....

I'm trying to figure out how to calculate the total rate per person based on the radio button (i.e. Method of Compensation) selected.

Scenario:  Based on what type of premium work performed (overtime, holiday, comp time) will determine the percentage of their hourly rate in which they will be paid.  Not sure if it would be easier to deal with decimals.

- Overtime 1.5 or 150%

- Holiday 2.0 or 200%

- Comp Time 0 or 0%

 

Sample portion of form is below:

Erika33040265wonq_0-1697741681567.png

Thanks in advance!

 

TOPICS
Acrobat SDK and JavaScript
544
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

Let's say your radio buttons are named "Group1" with export values of 1.5, 2, and 0.

If you already use a custom calculation script in your 'Total' field, add this after your script:

var rb = this.getField("Group1");
if(rb.valueAsString == "1.5" || rb.valueAsString == "2")
event.value = Number(event.value)*Number(rb.valueAsString);

 

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
New Here ,
Nov 15, 2023 Nov 15, 2023

Sorry for the late response.  I had a chance to go back and I don't know if it's my version of Adobe but I'm not seeing an option to add a value to a radio button.  Would it be easier to create a drop down with values?  This is the only option I have when I go into properties.

Erika33040265wonq_0-1700083062308.png

 

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 ,
Nov 15, 2023 Nov 15, 2023

There you use the value 1.5%

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 ,
Nov 16, 2023 Nov 16, 2023
LATEST

If you're going to use it in a calculation the value needs to be just a number (no "%") and adjusted to be a percentage, so use "0.015" for "1.5%", "0.02" for "2%", etc.

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