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

Checkbox is set to disable 9 fields when checked but one field is disable when the document opens

Community Beginner ,
Sep 10, 2024 Sep 10, 2024
if (event.target.value == "Off") //Checkbox "I will not be using air travel"
{
this.getField("air-noptoTravelOut:date").readonly=false
this.getField("air-noptoTravelReturn:date").readonly=false
this.getField("nopto-airfareCost").readonly=false
this.getField("attach-flightNopto").readonly=false
this.getField("air-ptoTravelOut:date").readonly=false
this.getField("air-ptoTravelReturn:date").readonly=false
this.getField("pto-airfareCost").readonly=false
this.getField("attach-flighPto").readonly=false
}
else
{
this.getField("air-noptoTravelOut:date").readonly = true;
this.getField("air-noptoTravelReturn:date").readonly=true;
this.getField("nopto-airfareCost").readonly=true;
this.getField("attach-flightNopto").readonly=true;
this.getField("air-ptoTravelOut:date").readonly=true;
this.getField("air-ptoTravelReturn:date").readonly=true;
this.getField("pto-airfareCost").readonly=true;
this.getField("attach-flightPto").readonly=true;
}

I am designing a form where the are multiple sections.  In one section, there is a checkbox the user can check off to indicate that the section its associated with does not apply to them.  I have added MouseUp JavaScript (with the help of this forum) to disable all 9 fields associated with that section when the user checks the box.  The defaut unchecked.

 

The problem comes when the user opens the form.  Upon launch, regardless of the default application to hand the PDF, the frist of the nine fields is disabled.  The only way I have found to enable that field is to check the box, then uncheck it.  My thought is to add JavaScript to check the box, then uncheck it immediately upon opening it, but that feels like a bad way to handle it.

 

Any ideas on how to deal with this, and if the solution I just proposed  is the way to do it, how to apply JS to run at launch?

 

i have provided the only JS code I have in the document at this point.

 

TOPICS
JavaScript , PDF forms
482
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 ,
Sep 10, 2024 Sep 10, 2024

All you have to do is add your script as a document level script.  It will run every time the document opens.  However, you must change event.target to this.getField("field name").  This article explains how to enter a document level script:

https://pdfautomationstation.substack.com/p/document-level-scripts

 

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 ,
Sep 10, 2024 Sep 10, 2024

All you have to do is add your script as a document level script.  It will run every time the document opens.  However, you must change event.target to this.getField("field name").  This article explains how to enter a document level script:

https://pdfautomationstation.substack.com/p/document-level-scripts

 

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 Beginner ,
Sep 13, 2024 Sep 13, 2024

Thank you.  Unfortunately, this is how I had to handle this, but creating a document level script to check and then uncheck the fields.  The linked article is a bit dated and is unclear on exactly how to get to the document-level Javascript console.  For the lates version of Acrobat as of this writing, you need to go to the All Tools menu and select Prepare a form.  Then click the 3 dots to the right of "Prepare a form" and select Document javascript.

motivated_art3594_0-1726238890803.png

 

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 ,
Sep 13, 2024 Sep 13, 2024
LATEST

When you select 'Prepare form' tool, you can use a shortcut to open document JavaScript SHIFT+D.

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 ,
Sep 10, 2024 Sep 10, 2024

You have an error in last field name, missing letter t:

"attach-flighPto"
"attach-flightPto"

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