Skip to main content
Participant
March 14, 2023
Question

Newbie: Exclude Selection - 3 Drop Down Menus

  • March 14, 2023
  • 3 replies
  • 1276 views

I am a newbie  to JS and have searched all over but cant seem to find a solution. I want to be able to exclude a selection from a drop down if already selected previously. I have 3 dropdowns with the same 4 selections

 

I would like if a user selects 'Customer Service' in dropdown "Most" then it should not show as an option on "Important" or "Least" drop downs, and if  the same user then selects 'Productivity' under "Important" dropdown then "Least" should only have the option of selecting 'Safety'

 

MostImportantLeast
Select OneSelect OneSelect One
Customer ServiceCustomer ServiceCustomer Service
ProductivityProductivityProductivity
SafetySafetySafety

 

I am probably taking the wrong approach but this is what I have in the "Most" Custom Keystroke Script (and I have modified one in the 'Important'): 

var f = this.getField("Important");

switch(event.value){

case "Select One":
f.setItems(["Select One", "Customer Service", "Productivity", "Safety"]);
break;

case "Customer Service":
f.setItems(["Select One", "Productivity", "Safety"]);
break;

case "Productivity":
f.setItems(["Select One", "Customer Service", "Safety"]);
break;

case "Safety":
f.setItems(["Select One", "Customer Service", "Productivity"]);
}

Thank you in advance. 

 

This topic has been closed for replies.

3 replies

try67
Community Expert
Community Expert
March 15, 2023

It's much easier (although less user-friendly) to reject the selected value if it's already selected in one of the other fields, instead of changing them each time a selection is made to remove the selected item, or revert them back to the original list.

Thom Parker
Community Expert
Community Expert
March 15, 2023

This is a difficult issue to solve, there is no easy solution, but there is a solution here:

https://www.pdfscripting.com/public/Multiple-Lists-Unique-selection-Description.cfm

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
ls_rbls
Community Expert
Community Expert
March 15, 2023

Ahh! great... yes, the hidden field.

 

This involves employing a global variable too correct?

Thom Parker
Community Expert
Community Expert
March 15, 2023

No global variables, just the hidden field.  But this is a complex process to manage. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
ls_rbls
Community Expert
Community Expert
March 15, 2023

Hi @Jacqueline28878900f8j4,

 

What seemed to work for me is not elegant but it may work for you.

 

What I did is shown below:

 

 

 

function myDropMenus() {

var f = event.target;
var most = this.getField("Most").valueAsString;
var important = this.getField("Important").valueAsString;

if (event.source && event.source.name == "Important") {

if (important == "Productivity") {
this.getField("Least").setItems(["Select One", "Safety"]);
  }

} else {

if (event.source && event.source.name == "Most") {

if (most == "Select One") {

f.setItems(["Select One", "Customer Service", "Productivity", "Safety"]);
}

if (most == "Customer Service") {

f.setItems(["Select One", "Productivity", "Safety"]);
}

if (most == "Productivity") {

f.setItems(["Select One", "Customer Service", "Safety"]);
}

if (most == "Safety") {

f.setItems(["Select One", "Customer Service", "Productivity"]);
    }
   }
  }

}

 

 

 

I added this function as a document-level script.

 

Call the function from fields "Important" and "Least" as a Custom Calculation Script:

 

 

 

myDropMenus();

 

 

 

 

NOTE:

 

Although this is an entirely different twist to what you originally posted, I hope that this works for you.

 

However, let's say that a user doesn't selects anything on field "Most" but decides to jump straight to field "Important" and choose "Productivity", and then selects "Safety" on field "Least", be aware that that whatever is selected on field "Most" will take precedence based off of the script and basically reset the "Important" and "Least" fields respectively (loosing their current values).

 

In the same context, changing a selection in field "Important" (to other than "Productivity") and after the user has made already made a selection on field "Least", won't have any effect on field "Least".

 

If this is not the behavior that you want, the script needs to be tweaked a little more.

 

Although I tested the script on a laptop computer, I am currently replying from a mobile device.

 

If you encounter any typos or errors in the script let me know.