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

If/and(?) for check boxes

Contributor ,
Jan 13, 2024 Jan 13, 2024

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!

 

TOPICS
How to , JavaScript , PDF forms
1.0K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Jan 13, 2024 Jan 13, 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);

View solution in original post

Translate
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 ,
Jan 13, 2024 Jan 13, 2024

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

Translate
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
Contributor ,
Jan 13, 2024 Jan 13, 2024

It may need to be manually checked

Thanks

Translate
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 ,
Jan 13, 2024 Jan 13, 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);
Translate
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
Contributor ,
Jan 14, 2024 Jan 14, 2024
LATEST

Wonderful - thank you @Nesa Nurani 

Translate
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 ,
Jan 13, 2024 Jan 13, 2024

Here are some articles that will help:

https://www.pdfscripting.com/public/How-to-write-an-If-statement.cfm

https://www.pdfscripting.com/public/PDF-Form-Scripting.cfm

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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
Contributor ,
Jan 13, 2024 Jan 13, 2024

Thanks Thom, I'll have a look

Translate
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