Skip to main content
KRoss00
Participating Frequently
April 14, 2023
Question

Adobe forms - adding a simple calculation with two options

  • April 14, 2023
  • 1 reply
  • 1168 views

Hi there! Im hoping one of you clever folk can help me out.

 

I am creating an interactive form from which users can select four eductational units to purchase. Each of the units (1-4 / Check box 1-4) are $165.60 to purchase, or if they select 'Complete set' / Check box 5 they get all of the educational units at a cheaper price. 

 

Some users are missing that 'Complete set' / Check box 5 is cheaper and are manually selecting options 1-4 / Check boxes 1-4. So im wondering, can we force users to select either Check boxes 1-4 OR Check box 5? Or if users select 1-4 can it convert to a Check box 5 selection?

 

In my subtotal field / TextField1 can I add a script that says:

  • If user selects any of  'Check Box 1 - 4' then add combined price to total 
  • If user selects ALL checkboxes 1-4 /  then add 'Complete set' price of $621.00 (discounted price)
  • If user selects ALL checkboxes 1-5 then deselect 1-4, select checkbox 5 and  $621.00 to subtotal

Ive attached a picture that should hopefully help! Checkboxes are 1-5 and subtotal is TextField1.

 

Thanks in advance 🙂

This topic has been closed for replies.

1 reply

Nesa Nurani
Community Expert
April 14, 2023

If user selects 1-4 it will automatically select checkbox 5 and deselect 1-4.

 

Put this in checkboxes 1-4 as 'Mouse UP' action 'Run a JavaScript':

var c1 = this.getField("Check Box 1");
var c2 = this.getField("Check Box 2");
var c3 = this.getField("Check Box 3");
var c4 = this.getField("Check Box 4");
var c5 = this.getField("Check Box 5");

if(c1.isBoxChecked(0)&&c2.isBoxChecked(0)&&c3.isBoxChecked(0)&&c4.isBoxChecked(0)){
c1.checkThisBox(0,false);
c2.checkThisBox(0,false);
c3.checkThisBox(0,false);
c4.checkThisBox(0,false);
c5.checkThisBox(0,true);}
else
c5.checkThisBox(0,false);

 

Put this in checkbox 5 as 'Mouse UP' action 'Run a JavaScript':

var c1 = this.getField("Check Box 1");
var c2 = this.getField("Check Box 2");
var c3 = this.getField("Check Box 3");
var c4 = this.getField("Check Box 4");

c1.checkThisBox(0,false);
c2.checkThisBox(0,false);
c3.checkThisBox(0,false);
c4.checkThisBox(0,false);

 

Put this in "Total" field as 'Custom calculation script':

var t1 = 0;
var t2 = 0;
for(var i=1; i<=4; i++){
if(this.getField("Check Box "+i).valueAsString != "Off")
t1 += Number(this.getField("Check Box "+i).valueAsString);}
if(this.getField("Check Box 5").valueAsString != "Off")
t2 = Number(this.getField("Check Box 5").valueAsString);
event.value = t1+t2;

 

KRoss00
KRoss00Author
Participating Frequently
April 16, 2023

@Nesa Nurani you are amazing! Thank you so much! Thats perfect! 

 

If I want to apply this to two other sets of check boxes do I just update the checkbox references to 6-10 and 11-15?

 

Thank you so much for taking the time to help, it is greatly appreciated!