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

Multiple Field Validation to Turn On Checkbox

New Here ,
Jul 26, 2017 Jul 26, 2017

I'm using a simple javascript to validate a field, and turn on a checkbox based on the value of the field.  However, I'd like the validation to loop or cycle through multiple fields prior to turn on the checkbox.  Here's what I have:

this.getField("Check Box3").checkThisBox(0, (event.value=="0"));

this.getField("Check Box4").checkThisBox(0, (event.value>="1"));

TOPICS
Acrobat SDK and JavaScript , Windows
682
Translate
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 , Jul 27, 2017 Jul 27, 2017

OK, you can use this code as the custom calculation script of the hidden "AutoCalc" field:

var cbValue = true;

for (var i=1; i<=14; i++) {

    if (Number(this.getField("Dropdown"+i).value)>0) {

        cbValue = false;

        break;

    }

}

this.getField("checkbox3").checkThisBox(0, cbValue);

I had assumed the drop-down fields are named "Dropdown1", "Dropdown2", etc.

Translate
Community Expert ,
Jul 27, 2017 Jul 27, 2017

So what's your question, exactly?

On Thu, Jul 27, 2017 at 1:48 AM, phillip072399 <forums_noreply@adobe.com>

Translate
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 ,
Jul 27, 2017 Jul 27, 2017

l guess I should explain the whole scenario.

I have two grouped either/or check boxes.  These check boxes are turned on or off based on the values of 14 other dropbox fields.  If the value of the dropbox fields is <="0", checkbox3 is turned on, and checkbox4 is turned off.  If the value of the of the dropbox fields is >="1", the checkbox3 is turned off, and checkbox4 is turned on.

The following code has been placed in the validation section of each of the 14 fields:

this.getField("Check Box3").checkThisBox(0, (event.value=="0"));

this.getField("Check Box4").checkThisBox(0, (event.value>="1"));

the problem I'm having is that the checkboxes react to the last known activity, so if one of the dropbox fields is 1, and another is 0, the validation reacts to last known value change, rather than surveying the value of all 14 fields and determining if any of the fields are greater than 0.

How do I rewrite the code so that it does that?

Translate
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
Community Expert ,
Jul 27, 2017 Jul 27, 2017

You need to move the code to a calculation event, possibly of a hidden field.

However, I'm still not following exactly how it is supposed to work. You wrote:

If the value of the dropbox fields is <="0", checkbox3 is turned on, and checkbox4 is turned off.

Multiple fields don't have a single value... Some can have a value lower than 0, and others larger than 0, I'm guessing. Do you mean the total value? Any value? A majority? Please clarify.

Translate
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 ,
Jul 27, 2017 Jul 27, 2017

There are 14 dropbox fields with a selectable value of 0 - 50.

If any of these fields' values, at any time, is greater than "0", checkbox3 should be turned "off", and checkbox4 should be turned "on".

If all of the fields' values are at "0", then checkbox3 should be turned "on", and checkbox4 should be turned "off".

I am not calculating a total value of the dropbox fields, but that could be a work around.

Translate
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
Community Expert ,
Jul 27, 2017 Jul 27, 2017

OK, you can use this code as the custom calculation script of the hidden "AutoCalc" field:

var cbValue = true;

for (var i=1; i<=14; i++) {

    if (Number(this.getField("Dropdown"+i).value)>0) {

        cbValue = false;

        break;

    }

}

this.getField("checkbox3").checkThisBox(0, cbValue);

I had assumed the drop-down fields are named "Dropdown1", "Dropdown2", etc.

Translate
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 ,
Jul 27, 2017 Jul 27, 2017
LATEST

Perfect.  Thank you.  The hidden field route works.

Translate
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