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

I have 2 check boxes made mutually exclusive, but each needs its own javascript. Can that be controlled with the export value of each check box? If yes, how do I code

Community Beginner ,
Aug 30, 2017 Aug 30, 2017

The standard selection is to select Sets, however Form must be able to handle when a Customer only wants one piece of a set.  So when Pieces is selected in the drop down, I have 2 mutually exclusive Check Boxes that turn on.  However dependent on which check box is selected I need each check box to have independent code from each other.  The code will open certain fields to complete and hide others.  The code is nearly reversible between the two.  Can this be done by testing for the export value of the check box?  If yes how do I code?

TOPICS
PDF forms
1.8K
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
1 ACCEPTED SOLUTION
Community Expert ,
Aug 31, 2017 Aug 31, 2017

Okay, perhaps I interpreted the term "mutually exclusive" differently than you meant it, but in any case, 2 (or any number of) checkboxes with the same name are not functioning as checkboxes, but as radio buttons. (Simply put, they can't be selected simultaneously; selecting one de-selects the other, right? This is ostensibly what you meant by 'mutually exclusive.')

So here it is, altered for that scenario (2 checkboxes, named identically, one with an export value of yes, the other with a value of no):

var cbox = this.getField("2checkboxes");

if (cbox.value == "yes")

    {

    // Show the relevant fields

     this.getField("field1").display = display.visible;

     this.getField("field2").display = display.visible;

     this.getField("field3").display = display.visible;

    // Hide the irrelevant fields

     this.getField("field4").display = display.hidden;

     this.getField("field5").display = display.hidden;

     this.getField("field6").display = display.hidden;

     }

if (cbox.value == "no")

    {

    // Show the relevant fields

     this.getField("field4").display = display.visible;

     this.getField("field5").display = display.visible;

     this.getField("field6").display = display.visible;

    // Hide the irrelevant fields

     this.getField("field1").display = display.hidden;

     this.getField("field2").display = display.hidden;

     this.getField("field3").display = display.hidden;

      }

View solution in original post

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 ,
Aug 31, 2017 Aug 31, 2017

Here some simple example code:

var cbox1 = this.getField("checkbox1");

var cbox2 = this.getField("checkbox2");

if (cbox1.value == "exportvalue")

    {

    // Show the relevant fields

     this.getField("field1").display = display.visible;

     this.getField("field2").display = display.visible;

     this.getField("field3").display = display.visible;

    // Hide the irrelevant fields

     this.getField("field4").display = display.hidden;

     this.getField("field5").display = display.hidden;

     this.getField("field6").display = display.hidden;

     }

if (cbox2.value == "exportvalue")

    {

    // Show the relevant fields

     this.getField("field4").display = display.visible;

     this.getField("field5").display = display.visible;

     this.getField("field6").display = display.visible;

    // Hide the irrelevant fields

     this.getField("field1").display = display.hidden;

     this.getField("field2").display = display.hidden;

     this.getField("field3").display = display.hidden;

      }

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 Beginner ,
Aug 31, 2017 Aug 31, 2017

When I make the 2 Checkboxes mutually exclusive they have the same name, so how do I reference the Check Box to setup the variables as you show below?

Tom

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 ,
Aug 31, 2017 Aug 31, 2017

Okay, perhaps I interpreted the term "mutually exclusive" differently than you meant it, but in any case, 2 (or any number of) checkboxes with the same name are not functioning as checkboxes, but as radio buttons. (Simply put, they can't be selected simultaneously; selecting one de-selects the other, right? This is ostensibly what you meant by 'mutually exclusive.')

So here it is, altered for that scenario (2 checkboxes, named identically, one with an export value of yes, the other with a value of no):

var cbox = this.getField("2checkboxes");

if (cbox.value == "yes")

    {

    // Show the relevant fields

     this.getField("field1").display = display.visible;

     this.getField("field2").display = display.visible;

     this.getField("field3").display = display.visible;

    // Hide the irrelevant fields

     this.getField("field4").display = display.hidden;

     this.getField("field5").display = display.hidden;

     this.getField("field6").display = display.hidden;

     }

if (cbox.value == "no")

    {

    // Show the relevant fields

     this.getField("field4").display = display.visible;

     this.getField("field5").display = display.visible;

     this.getField("field6").display = display.visible;

    // Hide the irrelevant fields

     this.getField("field1").display = display.hidden;

     this.getField("field2").display = display.hidden;

     this.getField("field3").display = display.hidden;

      }

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 Beginner ,
Aug 31, 2017 Aug 31, 2017
LATEST

Yes, thanks that’s what I needed.

Tom

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