Skip to main content
Participating Frequently
January 28, 2025
Answered

Dropdown reverts to first choice when saved

  • January 28, 2025
  • 3 replies
  • 655 views

I've got a form that I created that has two dropdown options, Division and Department.  When you select a Division, it only shows the the Departments available for that Division.  Whenever you save the document, the Department field goes blank but the Division field stays correct.  The code I have is this.  Any ideas on what I screwed up?

if (this.getField("Division_1").value == "Select One"){
    
       this.getField("Department_1").setItems(["Select One"])
    
}

else if (this.getField("Division_1").value == "Information Technology"){

   this.getField("Department_1").setItems(["Select One", "IT Applications Administration", "IT Applications Development", "IT Applications Operations", "IT Applications Support/CMS", "IT Security", "IT Network Services", "IT Helpdesk", "Project Management"])

}

else if (this.getField("Division_1").value == "Court Services"){

   this.getField("Department_1").setItems(["Select One", "Court Data Specialists", "Court Interpreting", "Court Reporting", "Judges' Scheduling", "Trial Court Services"])

}

else if (this.getField("Division_1").value == "Court Education"){

   this.getField("Department_1").setItems(["N/A"])

}

else if (this.getField("Division_1").value == "Human Resources"){

   this.getField("Department_1").setItems(["N/A"])

}

else if (this.getField("Division_1").value == "Public Information"){

   this.getField("Department_1").setItems(["N/A"])

}

else if (this.getField("Division_1").value == "State Court Administrator"){

   this.getField("Department_1").setItems(["N/A"])

}

 

Correct answer PDF Automation Station

Remove your existing scripts.  Make sure "Commit selected value immediately" is checked in the options tab of Division_1.  Enter the following Mouse Down script in the Department_1 field:

 

if (this.getField("Division_1").value == "Select One")
{event.target.setItems(["Select One"])}
else if (this.getField("Division_1").value == "Information Technology")
{event.target.setItems(["Select One", "IT Applications Administration", "IT Applications Development", "IT Applications Operations", "IT Applications Support/CMS", "IT Security", "IT Network Services", "IT Helpdesk", "Project Management"])}
else if (this.getField("Division_1").value == "Court Services")
{event.target.setItems(["Select One", "Court Data Specialists", "Court Interpreting", "Court Reporting", "Judges' Scheduling", "Trial Court Services"])}
else
{event.target.setItems(["N/A"])}

 

 

3 replies

PDF Automation Station
Community Expert
Community Expert
January 29, 2025

Remove your existing scripts.  Make sure "Commit selected value immediately" is checked in the options tab of Division_1.  Enter the following Mouse Down script in the Department_1 field:

 

if (this.getField("Division_1").value == "Select One")
{event.target.setItems(["Select One"])}
else if (this.getField("Division_1").value == "Information Technology")
{event.target.setItems(["Select One", "IT Applications Administration", "IT Applications Development", "IT Applications Operations", "IT Applications Support/CMS", "IT Security", "IT Network Services", "IT Helpdesk", "Project Management"])}
else if (this.getField("Division_1").value == "Court Services")
{event.target.setItems(["Select One", "Court Data Specialists", "Court Interpreting", "Court Reporting", "Judges' Scheduling", "Trial Court Services"])}
else
{event.target.setItems(["N/A"])}

 

 

Participating Frequently
January 29, 2025

That did it.  Thank you SO MUCH!

Nesa Nurani
Community Expert
Community Expert
January 29, 2025

Use the script in "Division_1" field as 'Validate' script, and replace.

this.getField("Division_1").value

with

event.value

Since you use multiple conditions for "N/A" you can shorten script like this:

if (event.value == "Select One"){
 this.getField("Department_1").setItems(["Select One"]);}

else if (event.value == "Information Technology"){
 this.getField("Department_1").setItems(["Select One", "IT Applications Administration", "IT Applications Development", "IT Applications Operations", "IT Applications Support/CMS", "IT Security", "IT Network Services", "IT Helpdesk", "Project Management"]);}

else if (event.value == "Court Services"){
 this.getField("Department_1").setItems(["Select One", "Court Data Specialists", "Court Interpreting", "Court Reporting", "Judges' Scheduling", "Trial Court Services"]);}

else if (event.value == "Court Education" || event.value == "Human Resources" || event.value == "Public Information" || event.value == "State Court Administrator"){
 this.getField("Department_1").setItems(["N/A"]);}
Participating Frequently
January 29, 2025

When I do it with the script you provided in the Validate tab then it shows ALL the options under the Department, not the selections.  The way I had it before was in the Calculate Tab under the Custom Calculation Script on the Division_1 field and it would show the correct options in the Department field but the Department field would disappear when you save it.  

PDF Automation Station
Community Expert
Community Expert
January 28, 2025

Where did you put this script?

Participating Frequently
January 28, 2025

I put the script under the last tab under the properties of the dropdown.  In the bottom box.  I'm not in front of it right now to give the exact tab / field.  Does it need to be somewhere else?

PDF Automation Station
Community Expert
Community Expert
January 28, 2025

It matters which field and which type of script (calculation, validation, format, etc.)