• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Dec 20, 2017 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.

TOPICS
Acrobat SDK and JavaScript

Views

497

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
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 20, 2017 Dec 20, 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

...

Votes

Translate

Translate
Community Expert ,
Dec 20, 2017 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

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
New Here ,
Dec 20, 2017 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.

Votes

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
community guidelines
New Here ,
Dec 20, 2017 Dec 20, 2017

Copy link to clipboard

Copied

LATEST

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!

Votes

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
community guidelines