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

Mouseup event to toggle check boxes

Community Beginner ,
Aug 29, 2021 Aug 29, 2021

Copy link to clipboard

Copied

Hi I was just wondering if someone was able to give me a hand with some javascript, I have a form with a variety of check boxes all with different export values which is used for another scripting function. I would like a button to check/uncheck specific boxes.

Example:

var MyVar="box1", "check7", "Sample2";
if(this.getField("MyVar").isChecked()); {
this.getField("myVar).checked(0,false)
} else {
this.getField("myVar).checked(0,true)
app.alert("Your default boxes have been checked.",0);
}

 Thanks in advance for your help

TOPICS
JavaScript , PDF forms

Views

460

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 , Aug 29, 2021 Aug 29, 2021

Try like this:

var MyVar = ["box1", "check7", "Sample2"];
var total = 0;
for (var i in MyVar){
if(this.getField(MyVar[i]).isBoxChecked(0))
this.getField(MyVar[i]).checkThisBox(0,false);
else{
this.getField(MyVar[i]).checkThisBox(0,true);
if(this.getField(MyVar[i]).isBoxChecked(0))total++;
if(total == 3)
app.alert("Your default boxes have been checked.",0);}}

 

Will all 3 checkboxes always be at same state? Because if some are checked and others unchecked script won't  work as intended.

 

 

Votes

Translate

Translate
Community Expert ,
Aug 29, 2021 Aug 29, 2021

Copy link to clipboard

Copied

Try like this:

var MyVar = ["box1", "check7", "Sample2"];
var total = 0;
for (var i in MyVar){
if(this.getField(MyVar[i]).isBoxChecked(0))
this.getField(MyVar[i]).checkThisBox(0,false);
else{
this.getField(MyVar[i]).checkThisBox(0,true);
if(this.getField(MyVar[i]).isBoxChecked(0))total++;
if(total == 3)
app.alert("Your default boxes have been checked.",0);}}

 

Will all 3 checkboxes always be at same state? Because if some are checked and others unchecked script won't  work as intended.

 

 

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 ,
Aug 30, 2021 Aug 30, 2021

Copy link to clipboard

Copied

LATEST

Thanks Nesa, worked like a charm! 8)👍

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