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

Checkbox with value

New Here ,
Feb 28, 2025 Feb 28, 2025

Copy link to clipboard

Copied

Hello, I'm new to this. I need some help on the script for an interactive form. 
I have three checkboxes that have their values, when I click, I want their values to reflect on the text field.
Checkbox 1 = 0 points
Checkbox  2 = 2 points
Checkbox 3 = 2 points

Also, is it possible to only be able to click one among the checkboxes or should this be Radio Buttons?
Thank you.

TOPICS
PDF , PDF forms

Views

60
Translate

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 guidelines
1 ACCEPTED SOLUTION
New Here ,
Feb 28, 2025 Feb 28, 2025

Copy link to clipboard

Copied

LATEST

I played around with the JavaScript and based it on the others' answers. More importantly, I changed the checkbox to Radio Buttons just to avoid the possibility that the user will accidentally click the other checkbox: 

var total = 0;

var values = {
"Radio Button1": {
"1": 0,
"2": 2,
"3": 2
}
};

var selectedValue = this.getField("RB7").value;

if (selectedValue && values["Radio Button1"][selectedValue] !== undefined) {
total += values["Radio Button1"][selectedValue];
}

event.value = total;

View solution in original post

Votes

Translate

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 guidelines
Community Expert ,
Feb 28, 2025 Feb 28, 2025

Copy link to clipboard

Copied

To make only one field selectable you need to give them the same name, but unique export values. Usually the values in points should be the export value, but if two have the same value, that won't work. So use "Choice1", "Choice2" and "Choice3". Then, as the custom calculation script of the text field enter the following (let's say the fields are named "CheckboxGroup1"):

 

var cb = this.getField("CheckboxGroup1").valueAsString;
if (cb=="Off") event.value = "";
else if (cb=="Choice1") event.value = "0 points";
else event.value = "2 points";

Votes

Translate

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 guidelines
Community Expert ,
Feb 28, 2025 Feb 28, 2025

Copy link to clipboard

Copied

Votes

Translate

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 guidelines
New Here ,
Feb 28, 2025 Feb 28, 2025

Copy link to clipboard

Copied

LATEST

I played around with the JavaScript and based it on the others' answers. More importantly, I changed the checkbox to Radio Buttons just to avoid the possibility that the user will accidentally click the other checkbox: 

var total = 0;

var values = {
"Radio Button1": {
"1": 0,
"2": 2,
"3": 2
}
};

var selectedValue = this.getField("RB7").value;

if (selectedValue && values["Radio Button1"][selectedValue] !== undefined) {
total += values["Radio Button1"][selectedValue];
}

event.value = total;

Votes

Translate

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 guidelines