Skip to main content
Participating Frequently
Jan 28, 2025 8:55 PM UTC
Answered

Dropdown reverts to first choice when saved

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"])

}

 

PDF Automation Station
Community Expert
Jan 29, 2025 3:47 PM UTC

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"])}

 

 

13 replies

PDF Automation Station
Community Expert
Community Expert
Jan 29, 2025 3:47 PM UTC

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"])}

 

 

Translate
Participating Frequently
Jan 29, 2025 3:51 PM UTC

That did it.  Thank you SO MUCH!

Translate
Nesa Nurani
Community Expert
Community Expert
Jan 29, 2025 5:31 AM UTC

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"]);}
Translate
Participating Frequently
Jan 29, 2025 2:47 PM UTC

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.  

Translate
PDF Automation Station
Community Expert
Community Expert
Jan 28, 2025 9:39 PM UTC

Where did you put this script?

Translate
Participating Frequently
Jan 28, 2025 11:00 PM UTC

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?

Translate
PDF Automation Station
Community Expert
Community Expert
Jan 28, 2025 11:54 PM UTC

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

Translate