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

Checkboxes triggering another checkbox - toggling on/off issues

Community Beginner ,
Dec 20, 2017 Dec 20, 2017

Copy link to clipboard

Copied

I have series of parent checkboxes that trigger on child checkboxes - copying the value.  But if the user changes the parent checkbox from "On" to "off" the  child checkbox does not copy. This the script i founded was using

var nhnw2 = getField("ClientHNW2").value;

if (nhnw2 === "On")

{

  getField("ClientHNWSup2").value = "On"

} else {

  getField("ClientHNWSup2").value = "Off";

}

JJ

TOPICS
Acrobat SDK and JavaScript , Windows

Views

928

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

Also, this script is inefficient. As long as the parent and child have the same export values then this script will work better:

this.getField("ClientHNWSup2").value = event.target.value;

Votes

Translate

Translate
Community Expert ,
Dec 20, 2017 Dec 20, 2017

Copy link to clipboard

Copied

Is this script in the MouseUp event for one of the checkboxes?

Does the script work for turning the child On?

Did you change the checkbox export value to "On"?

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

Copy link to clipboard

Copied

Also, this script is inefficient. As long as the parent and child have the same export values then this script will work better:

this.getField("ClientHNWSup2").value = event.target.value;

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
Community Beginner ,
Dec 21, 2017 Dec 21, 2017

Copy link to clipboard

Copied

Them Parker

The code you supplied goes in the parent mouse up event?

JJ

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
Community Beginner ,
Dec 21, 2017 Dec 21, 2017

Copy link to clipboard

Copied

okay got it now - thank you Thom.

For anyone else reading you place

this.getField("NameOfChildCheckbox").value = event.target.value;

in the parent checkbox's > actions > mouse up > Execute menu item > Run a Javascript 

JJ

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

Copy link to clipboard

Copied

You had the right idea of using a document level script, because it reduces human error associated with entering code in each and every checkbox, and massively reduces the effort of making code changes.  This script is pretty simple though, so it's not as bad as something more complex.

That said, a better solution is to write a document level script that is totally generic, i.e., it requires no specific field name inputs, because it derives the name of the target client check box from the name of the checkbox where the script is running. This almost completely reduces human error. 

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
Community Beginner ,
Dec 21, 2017 Dec 21, 2017

Copy link to clipboard

Copied

LATEST

One day i figure out how to write generic scripts, i am just not there yet.

JJ

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
Community Beginner ,
Dec 21, 2017 Dec 21, 2017

Copy link to clipboard

Copied

Yes the script turned on the child checkbox. I had as document level script because i have 8 checkboxes to do the same thing with. Originally I had this function written

function checkControl() { 

 

    // Get a reference to each check box 

    var hnw2 = getField("ClientHNW2"); 

    var hnw3 = getField("ClientHNW3"); 

    var hnw4 = getField("ClientHNW4");

    var hnw5 = getField("ClientHNW5");  

    var pwm2 = getField("ClientPWM2"); 

    var pwm3 = getField("ClientPWM3"); 

    var pwm4 = getField("ClientPWM4"); 

    var pwm5 = getField("ClientPWM5");

    var hnwsup2 = getField("ClientHNWSup2"); 

    var hnwsup3 = getField("ClientHNWSup3"); 

    var hnwsup4 = getField("ClientHNWSup4");

    var hnwsup5 = getField("ClientHNWSup5");

    var pwmsup2 = getField("ClientPWMSup2");

    var pwmsup3 = getField("ClientPWMSup3"); 

    var pwmsup4 = getField("ClientPWMSup4"); 

    var pwmsup5 = getField("ClientPWMSup5");   

 

    // turning on an off checkboxes

    if (event.target === hnw2) { 

        hnwsup2.value = "On"; 

}

    if (event.target === hnw3) { 

        hnwsup3.value = "On";  

}

  if (event.target === hnw4) { 

        hnwsup4.value = "On"; 

}

    if (event.target === hnw5) { 

        hnwsup5.value = "On"; 

}

    if (event.target === pwm2) { 

        pwmsup2.value = "On"; 

}

    if (event.target === pwm3) { 

        pwmsup3.value = "On"; 

}

  if (event.target === pwm4) { 

        pwmsup4.value = "On"; 

}

    if (event.target === pwm5) { 

        pwmsup5.value = "On"; 

    }

   }

 

  // Mouse up run javascrip for each HWN or PWM checkbox on all pages and set export value to On

  //  checkControl(); 

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