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

New Here ,
Dec 20, 2017

Copy link to clipboard

Copied

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.

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

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

TOPICS
Acrobat SDK and JavaScript

Views

75

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

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

New Here ,
Dec 20, 2017

Copy link to clipboard

Copied

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.

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

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

TOPICS
Acrobat SDK and JavaScript

Views

76

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 20, 2017 0
Adobe Community Professional ,
Dec 20, 2017

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 20, 2017 0
New Here ,
Dec 20, 2017

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 20, 2017 0
New Here ,
Dec 20, 2017

Copy link to clipboard

Copied

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!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 20, 2017 0