Highlighted

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

New Here ,
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, Create PDFs, PDF forms

Views

38

Likes

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

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

New Here ,
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, Create PDFs, PDF forms

Views

39

Likes

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
Sep 16, 2020 0
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
Sep 16, 2020 0
New Here ,
Sep 16, 2020

Copy link to clipboard

Copied

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. 

Likes

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
Reply
Loading...
Sep 16, 2020 0