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

If and checkboxes - Auto checking a checkbox once 2 others are checked

New Here ,
Sep 16, 2020 Sep 16, 2020

Copy link to clipboard

Copied

The below statment will not check my checkbox3 once checkbox1 && checkbox2 are checked it will only work with the || (or) statement, what am I doing wroung? 

 

Document Level Control

 

function cbControl() {

// Get a reference to each check box

var f1 = getField("checkbox1");

var f2 = getField("checkbox2");

var f3 = getField("checkbox3");

 

// Check cb3 if cb1 and cb2 was selected

if (event.target === f1 && event.target === f2)

{ f3.value = "Yes"; return; }

}

 

Mouse Up Event on each checkbox

cbControl();

TOPICS
Acrobat SDK and JavaScript

Views

304

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 ,
Sep 16, 2020 Sep 16, 2020

Copy link to clipboard

Copied

Hi,

 

event.target cannot be equal to both f1 and f2, it is the target of the event ( so it will be either f1 or f2).

You need to change the code so that if event.target is f1, you use f2.value to work out if F2 is also checked.

And the same the other way round when event.target is f2.

 

Pleaes note: as this is a checkbox, there is no guarentee that the mouse up is for the checkbox being checked , it may be it being unchecked so you might want to check that value to make sure it is selected ( you can use event.value for the one that is being clicked).

 

hope that helps

 

Malcolm

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
New Here ,
Sep 16, 2020 Sep 16, 2020

Copy link to clipboard

Copied

LATEST

I am pretty new to Javascript... and not quite understanding exactly where to change the code? Would you be able to show me an example? 

 

Thanks in advance. 

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