Skip to main content
Known Participant
January 13, 2024
Answered

If/and(?) for check boxes

  • January 13, 2024
  • 2 replies
  • 1468 views

How do I write a JavaScript for the following please:

 

If PurchaseCheckBox AND Service1 are checked, automatically check ServiceCover

 

So if Service is checked on it's own, ServiceCover stays unchecked.

 

Thank you!

 

This topic has been closed for replies.
Correct answer Nesa Nurani

Put this script in both "PurchaseCheckBox" and "Service1" fields as 'Mouse UP' action (Run a JavaScript):

var pcb = this.getField("PurchaseCheckBox").valueAsString;
var s1 = this.getField("Service1").valueAsString;
var SC = this.getField("ServiceCover");

SC.checkThisBox(0,(pcb!=="Off"&&s1!=="Off") ? true : false);

2 replies

Thom Parker
Community Expert
Community Expert
January 13, 2024
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
jlehaneAuthor
Known Participant
January 13, 2024

Thanks Thom, I'll have a look

Nesa Nurani
Community Expert
Community Expert
January 13, 2024

Do you wish for 'ServiceCover' to be checked manually, or it needs to remain unchecked until both PurchaseCheckBox AND Service1 are checked?

jlehaneAuthor
Known Participant
January 13, 2024

It may need to be manually checked

Thanks

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
January 14, 2024

Put this script in both "PurchaseCheckBox" and "Service1" fields as 'Mouse UP' action (Run a JavaScript):

var pcb = this.getField("PurchaseCheckBox").valueAsString;
var s1 = this.getField("Service1").valueAsString;
var SC = this.getField("ServiceCover");

SC.checkThisBox(0,(pcb!=="Off"&&s1!=="Off") ? true : false);