Skip to main content
Participating Frequently
December 20, 2017
Answered

I have two checkboxes, how do I get a value of "1" if one or both are selected?

  • December 20, 2017
  • 1 reply
  • 813 views

I have a series of data points in an Acrobat Form. I have two checkboxes, and if either one or both are selected, I need a value of 1. I am not good at Javascript, and I think I am missing the very simple way to do it.

This topic has been closed for replies.
Correct answer Thom Parker

Where are these data points (in a text box, a list box?),

How are they set, and what is the relationship to the check boxes. are there two checks boxes per data point?

Where is this "1" going to be. 

Since the "1" value depends on two different inputs, a calculation script is a good place to put the code, because calculation scripts are run each time any field changes. So here's an example of a calculation script.

if((this.getField("check1").value == "Yes") || (this.getField("check2").value == "Yes"))

   event.value = 1;

else

{ display the thing that gets displayed when it's not "1"}

Here's an old tutorial on setting up calculations:

https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations

Here's lots more recent info:

Calculating field values and more

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
December 21, 2017

Where are these data points (in a text box, a list box?),

How are they set, and what is the relationship to the check boxes. are there two checks boxes per data point?

Where is this "1" going to be. 

Since the "1" value depends on two different inputs, a calculation script is a good place to put the code, because calculation scripts are run each time any field changes. So here's an example of a calculation script.

if((this.getField("check1").value == "Yes") || (this.getField("check2").value == "Yes"))

   event.value = 1;

else

{ display the thing that gets displayed when it's not "1"}

Here's an old tutorial on setting up calculations:

https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations

Here's lots more recent info:

Calculating field values and more

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
December 21, 2017

Will that work if my checkboxes export a value of a number rather than "yes"? This is for an entry form, and I have 20 lines with 10 items in each line. I need a variety of calculations, and selecting the checkboxes calculate fees (two entries per line), but I need to count how many lines have at least one entry.

Participating Frequently
December 21, 2017

Wait! I got it!!!!

if((this.getField("A1").value == "4") || (this.getField("B1").value == "4"))

   event.value = 1;

else

event.value = 0

This gives me "1" if A and/or B, and "0" if neither! Perfect! Thank you!