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

If/and(?) for check boxes

Contributor ,
Jan 13, 2024 Jan 13, 2024

Copy link to clipboard

Copied

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

Views

164

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 , 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);

Votes

Translate

Translate
Community Expert ,
Jan 13, 2024 Jan 13, 2024

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

It may need to be manually checked

Thanks

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

Copy link to clipboard

Copied

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);

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

Copy link to clipboard

Copied

LATEST

Wonderful - thank you @Nesa Nurani 

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

Thanks Thom, I'll have a look

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