Skip to main content
Participant
September 10, 2024
Answered

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

  • September 10, 2024
  • 2 replies
  • 671 views
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.

 

This topic has been closed for replies.
Correct answer PDF Automation Station

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

 

2 replies

Nesa Nurani
Community Expert
Community Expert
September 11, 2024

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

"attach-flighPto"
"attach-flightPto"

PDF Automation Station
Community Expert
Community Expert
September 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

 

Participant
September 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.

 

Nesa Nurani
Community Expert
Community Expert
September 13, 2024

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