Copy link to clipboard
Copied
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'
Most | Important | Least |
Select One | Select One | Select One |
Customer Service | Customer Service | Customer Service |
Productivity | Productivity | Productivity |
Safety | Safety | Safety |
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Ahh! great... yes, the hidden field.
This involves employing a global variable too correct?
Copy link to clipboard
Copied
No global variables, just the hidden field. But this is a complex process to manage.
Copy link to clipboard
Copied
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.