Skip to main content
phillip072399
Participant
July 26, 2017
Answered

Multiple Field Validation to Turn On Checkbox

  • July 26, 2017
  • 1 reply
  • 822 views

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"));

This topic has been closed for replies.
Correct answer try67

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.


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.

1 reply

try67
Community Expert
Community Expert
July 27, 2017

So what's your question, exactly?

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

phillip072399
Participant
July 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?

try67
Community Expert
Community Expert
July 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.