Skip to main content
Participant
January 6, 2020
Answered

Calculating field total based on sum of checkboxes multiplied by a radio button value

  • January 6, 2020
  • 1 reply
  • 3118 views

I have a transcript request form that I need to calculate a total dollar amount in a field at the bottom based on which options are selected. The form is set up like this:

 

Checkbox 1:  $5 mail unofficial transcript

Checkbox 2:  $5 mail official transcript

Checkbox 3:  $5 email transcript

 

Radio 1:  BSB transcript 

Radio 2:  degree transcript 

Radio 3:  both BSB and degree transcript ($5 each)

 

Text field total:  This amount should be the sum of the checkboxes (one or more can be selected, each valued at $5) and IF Radio 3 is selected, should be multiplied by 2 (so, if I want a transcript by mail and by email, for both BSB and degree, then my total would be $20; 5+5x2).

 

Is this possible?

This topic has been closed for replies.
Correct answer try67

Yes, it's possible. However, the radio-buttons should have the same name but unique "radio button choice" values, not unique names for each one (because that would mean that you could select multiple ones). Let's say they are all called "Radio" and their values are 1, 2 and 3. You can then use this code as the custom calculation script of your total field:

 

 

var total = 0;
if ((this.getField("Checkbox 1").valueAsString)!="Off") total+=5;
if ((this.getField("Checkbox 2").valueAsString)!="Off") total+=5;
if ((this.getField("Checkbox 3").valueAsString)!="Off") total+=5;
if ((this.getField("Radio").valueAsString)=="3") total*=2;
event.value = total;

 

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
January 6, 2020

Yes, it's possible. However, the radio-buttons should have the same name but unique "radio button choice" values, not unique names for each one (because that would mean that you could select multiple ones). Let's say they are all called "Radio" and their values are 1, 2 and 3. You can then use this code as the custom calculation script of your total field:

 

 

var total = 0;
if ((this.getField("Checkbox 1").valueAsString)!="Off") total+=5;
if ((this.getField("Checkbox 2").valueAsString)!="Off") total+=5;
if ((this.getField("Checkbox 3").valueAsString)!="Off") total+=5;
if ((this.getField("Radio").valueAsString)=="3") total*=2;
event.value = total;

 

Participant
January 6, 2020

I'm trying it, but it says there is a "syntax error 2: at line 3."

try67
Community Expert
Community Expert
January 6, 2020

Sorry, fixed it now.