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

Checkbox, select and disable.

Participant ,
Jun 03, 2016 Jun 03, 2016

I have code that when a specific checkbox is checked, several other checkboxes become checked. I need ONLY those other checkboxes that get Checked to now be greyedout/locked checked. So the only way to uncheck them would be to deselect the original checkbox. The code is below.....

var otherCheckBoxes = ["Local Travel", "Taxi", "Public Transit", "Province", "Region", "Private Motor Vehicle", "Government Fleet vehicle",  "Air1", "Rail1", "Bus1", "Ferry1", "Taxi3", "Rental Motor Vehicle1", "Public Transit1", "Private Motor Vehicle2",  "Government Fleet vehicle2", "Air", "Rail", "Bus", "Ferry", "Taxi2", "Rental Motor Vehicle", "Public Transit2", "Private Motor Vehicle1",  "Government Fleet vehicle1"]; // etc.

if (getField("Canada").value!="Off") {

for (var i in otherCheckBoxes) getField(otherCheckBoxes).checkThisBox(0,true);

}

else if  (getField("Canada").value!="On")  {

for (var i in otherCheckBoxes) getField(otherCheckBoxes).checkThisBox(0,false);

}

TOPICS
Acrobat SDK and JavaScript , Windows
818
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 , Jun 03, 2016 Jun 03, 2016

Change the last part of the code to:

if (this.getField("Canada").value!="Off") {

    for (var i in otherCheckBoxes) {

        this.getField(otherCheckBoxes).checkThisBox(0,true);

        this.getField(otherCheckBoxes).readonly = true;

    }

} else if (this.getField("Canada").value!="On")  {

    for (var i in otherCheckBoxes) {

        this.getField(otherCheckBoxes).checkThisBox(0,false);

        this.getField(otherCheckBoxes).readonly = false;

    }

}

Translate
Community Expert ,
Jun 03, 2016 Jun 03, 2016

Change the last part of the code to:

if (this.getField("Canada").value!="Off") {

    for (var i in otherCheckBoxes) {

        this.getField(otherCheckBoxes).checkThisBox(0,true);

        this.getField(otherCheckBoxes).readonly = true;

    }

} else if (this.getField("Canada").value!="On")  {

    for (var i in otherCheckBoxes) {

        this.getField(otherCheckBoxes).checkThisBox(0,false);

        this.getField(otherCheckBoxes).readonly = false;

    }

}

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 ,
Jun 03, 2016 Jun 03, 2016
LATEST

By the way, your code is a bit confusing. Why use the NOT-EQUALS operator instead of the EQUALS one? It would make it more readable.

It can even be simplified even more, to:

var isCanada = (this.getField("Canada").value!="Off");

for (var i in otherCheckBoxes) {

    this.getField(otherCheckBoxes).checkThisBox(0, isCanada);

    this.getField(otherCheckBoxes).readonly = isCanada;

}

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