Skip to main content
Participant
February 28, 2025
Answered

Checkbox with value

  • February 28, 2025
  • 3 replies
  • 414 views

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.

Correct answer opera27935047chyp

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;

3 replies

opera27935047chypAuthorCorrect answer
Participant
February 28, 2025

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;

PDF Automation Station
Community Expert
Community Expert
February 28, 2025
try67
Community Expert
Community Expert
February 28, 2025

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";