Skip to main content
Participating Frequently
July 12, 2022
Answered

When any of my 6 checkbox are checked, I would like to add a value to a text box

  • July 12, 2022
  • 2 replies
  • 1265 views

Hi all, 

 

Could anyone please help me? 

 

I have 6 checkboxes called CheckBox3 CheckBox4 CheckBox5 CheckBox6 CheckBox7 and CheckBox8. When the learner ticked any of those checkboxes, I would like to add the value of 45 to the textbox called Text21. If a learner ticks more than one checkbox, the value is still 45. If the learner does not tick any of the checkboxes, the vaue in Text21 is to be 0. 

 

How would I action this? 

 

    This topic has been closed for replies.
    Correct answer try67

    You can do it using this code as the custom calculation script of Text21:

     

    var anyFieldTicked = false;
    for (var i=3; i<=8; i++) {
    	if (this.getField("CheckBox"+i).valueAsString!="Off") {anyFieldTicked = true; break;}
    }
    event.value = anyFieldTicked ? 45 : 0;

    2 replies

    try67
    Community Expert
    try67Community ExpertCorrect answer
    Community Expert
    July 12, 2022

    You can do it using this code as the custom calculation script of Text21:

     

    var anyFieldTicked = false;
    for (var i=3; i<=8; i++) {
    	if (this.getField("CheckBox"+i).valueAsString!="Off") {anyFieldTicked = true; break;}
    }
    event.value = anyFieldTicked ? 45 : 0;
    Participating Frequently
    July 12, 2022

    Thank you so much, that worked. You are amazing!

    Could I be a pain and ask what would be the script if I wished to change it to award different values based on the checkbox you ticked. So CheckBox3 award 10,  CheckBox4 award 20, CheckBox5 award 30, CheckBox6 award 15, CheckBox7 award 30 and CheckBox8 award 45 to the textbox called Text21? 

    try67
    Community Expert
    Community Expert
    July 12, 2022

    Just set these numbers as their export values, and then use the built-in Sum command to add them all up...

    John Waller
    Community Expert
    Community Expert
    July 12, 2022

    Which Adobe app are you using? Acrobat?

    Participating Frequently
    July 12, 2022

    Hi John, 

     

    I am using Acrobat Pro. 

    John Waller
    Community Expert
    Community Expert
    July 12, 2022

    Question moved from Using the Community forum.