# Disable Options in Dropdown Menu

**URL:** <https://forums.knack.com/t/disable-options-in-dropdown-menu/7734>\
**Category:** Ask Developers\
**Created:** [January 31, 2016, 3:51pm UTC](https://forums.knack.com/t/disable-options-in-dropdown-menu/7734 "2016-01-31T15:51:27Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChrisAgnew79606](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@ChrisAgnew79606](https://forums.knack.com/u/ChrisAgnew79606)\
**Post date:** [January 31, 2016, 3:51pm UTC](https://forums.knack.com/t/disable-options-in-dropdown-menu/7734/1 "2016-01-31T15:51:27Z")

</div>

In my app, each user selects one "player" per week and then is no longer able to use that same "player" again. I am looking for a way to disable the previously selected "player" from a dropdown menu, based off of the logged in user's previous selections. It seems that I need to add in a custom code in order to do this, but I really have no idea where to begin. Any help that can be offered, would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![BennetSt.L83204](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@BennetSt.L83204](https://forums.knack.com/u/BennetSt.L83204)\
**Post date:** [February 17, 2016, 6:35pm UTC](https://forums.knack.com/t/disable-options-in-dropdown-menu/7734/2 "2016-02-17T18:35:34Z")

</div>

We could do that - the only downside I see is that some browsers will allow you to disable those alerts. If your comfortable with that, I can make that change. (Well take all of 30 seconds).

Let me know.

---

<div class="post-metadata">

**Author:** ![ChrisAgnew79606](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@ChrisAgnew79606](https://forums.knack.com/u/ChrisAgnew79606)\
**Post date:** [February 17, 2016, 6:28pm UTC](https://forums.knack.com/t/disable-options-in-dropdown-menu/7734/3 "2016-02-17T18:28:17Z")

</div>

Bennet,

Thank you for checking back and my apologies for the delayed response. The solution is great!! Thank you very much for the help. The only question I had is regarding the message "You have already selected this golfer". Is it at possible to have that in a pop up message when a user tries to press submit, vs. it just populating on the page?

No big deal, just looking out for those who fail to see the message (even though I changed it to bold letters and red font). Otherwise, it's great and again, thank you much for the help.

---

<div class="post-metadata">

**Author:** ![BennetSt.L83204](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@BennetSt.L83204](https://forums.knack.com/u/BennetSt.L83204)\
**Post date:** [February 17, 2016, 3:27pm UTC](https://forums.knack.com/t/disable-options-in-dropdown-menu/7734/4 "2016-02-17T15:27:43Z")

</div>

Chris,

Just wondering if you had a chance to take a look, and make sure it is working to your specifications. Let me know if there is anything I need to change or update.

Thanks!

---

<div class="post-metadata">

**Author:** ![BennetSt.L83204](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@BennetSt.L83204](https://forums.knack.com/u/BennetSt.L83204)\
**Post date:** [February 11, 2016, 4:13am UTC](https://forums.knack.com/t/disable-options-in-dropdown-menu/7734/5 "2016-02-11T04:13:23Z")

</div>

Alright you're all set -

Chris, you'll notice a Rich Text and Table on the scene that your form submission is on. The Rich Text is what will show to your user when they try to select an option they've already used. (Perhaps a place for a funny picture, but that may just be me) and the table will determine what options are not allowed for another selection. Reminder, if there are multiple pages of information in the table, it will only use page 1. (I set the default to 50 records, sounds like that should be plenty)

Below is the noted code for anyone interested

```
//Function to determine if the selected option has already been selected based off the table populating (see below)
function change_golfer () {
    //Finds index of current selection and gets the text of that selection
	var x = select_connect.selectedIndex
    sel_golfer = select_connect.options[x].text

```
//Loops thru golfers previously selected and checks if selection has been used in the past
for (j = 0; j &lt; golfers.length; j++) {

//If match is found - displays the msg for the duplicate text and sets a boolean to true, ends loop
  if (sel_golfer == golfers[j]) {
    already_select = true
    dup_msg.style.visibility = "visible";
    break;
  }
  //if Match is not found hides the duplicate text and set the boolean to false
  else {
    dup_msg.style.visibility = "hidden";
    already_select = false;
  }

}

```

}

$(document).on(‘knack-scene-render.scene\_72’, function() {

//Find field that the user will be selecting from  
select\_connect = document.getElementById(“view\_172-field\_179”);

//Find field that contains the message if the user selects a duplicate entry  
dup\_msg = document.getElementById(“view\_177”)

//Hide the Duplicate message by default  
dup\_msg.style.visibility = “hidden”

//Call the functions to check the if the default selection has been used  
change\_golfer()

//When the selection is change, call the check function  
$(’#view\_172-field\_179’).on(‘change’, change\_golfer)

//When the submit button is clicked, if the current selection is a duplicate, nothing is submitted  
$("#view\_172 .kn-submit input[type=submit]").on(“click”, function() {  
if (already\_select == true) {  
return false;  
}

})

})

//Gathers the data from past selections and puts into an array for use when checking  
//Could have been done with an API call as well  
//Using table allows user to change criteria thru the interface rather than changing an API call  
$(document).on(‘knack-view-render.view\_176’, function (event, view, data) {  
golfers = ]  
for (i = 0; i \< data.length; i++) {  
golfers[i] = data[i].field\_179\_raw[0].identifier;  
//Remove the “//” from the lines below if you want to hide the table  
//var data\_table = document.getElementById("#view\_176");  
//data\_table.style.visibility = “hidden”;  
}  
})
```

---

<div class="post-metadata">

**Author:** ![ChrisAgnew79606](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@ChrisAgnew79606](https://forums.knack.com/u/ChrisAgnew79606)\
**Post date:** [February 10, 2016, 7:51pm UTC](https://forums.knack.com/t/disable-options-in-dropdown-menu/7734/6 "2016-02-10T19:51:25Z")

</div>

Yes sir, will do. Thanks again and please let me know if anything else is needed from my end.

---

<div class="post-metadata">

**Author:** ![BennetSt.L83204](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@BennetSt.L83204](https://forums.knack.com/u/BennetSt.L83204)\
**Post date:** [February 10, 2016, 7:09pm UTC](https://forums.knack.com/t/disable-options-in-dropdown-menu/7734/7 "2016-02-10T19:09:40Z")

</div>

It would be per User so we should be fine then.

I'll add the table and everything here tonight when I'm off work. If you could leave the data in there for now (gives us something to validate the code off of).

---

<div class="post-metadata">

**Author:** ![ChrisAgnew79606](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@ChrisAgnew79606](https://forums.knack.com/u/ChrisAgnew79606)\
**Post date:** [February 10, 2016, 6:45pm UTC](https://forums.knack.com/t/disable-options-in-dropdown-menu/7734/8 "2016-02-10T18:45:24Z")

</div>

Bennet,

Sorry for the delayed response. The outside of the box solution sounds like it will work just fine! Would the "100 at a time" number be per user or for all users? If it's per user as he/she is logged in, we're fine. There will only be 24 selections per user, per year. I am planning on wiping out the 2015 data and starting fresh.

Please let me know if you need anything else from my end. Thank you very much for the help provided and working through this one with me.

---

<div class="post-metadata">

**Author:** ![BennetSt.L83204](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@BennetSt.L83204](https://forums.knack.com/u/BennetSt.L83204)\
**Post date:** [February 5, 2016, 10:26pm UTC](https://forums.knack.com/t/disable-options-in-dropdown-menu/7734/9 "2016-02-05T22:26:23Z")

</div>

Well I've never worked with the Connections drop down fields in this manner and its proving to be interesting.

It doesn't appear that the options are in the HTML unlike "Multiple Selection" field in the DB. Unforunately, that means we can't just remove the options at will. (It might be possible but its beyound my knowledge)

Out side the box solution - I can't think of a way to stop them from seeing a selection that the User has already used, however we could make it so that if they do select a Player that they've already used, that an alert on their browser (or a text field on the form, however you'd want to do it) would appear telling them "Sorry..." and the "Submit" button would be disabled and prevent them from continuing.

Since we need access to their past selections, the easiest way would be to put this in a table below the form. This stipulation is that it needs to show ALL of their past selections and Knack renders up to a 100 at a time (didn't dive into your data to see if that number was going to be a problem or not). You could tailor the table to show whatever selections you want (only last X months for the User, All for the User, etc) and when Knack loaded the page, it would use whatever data was going into that table as the deciding factor for above.

If this sounds like an acceptable solution to you - let me know. I can write the code for you (would need to create a login to the actual UI for myself so I can see the HTML on the render).

---

<div class="post-metadata">

**Author:** ![BennetSt.L83204](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@BennetSt.L83204](https://forums.knack.com/u/BennetSt.L83204)\
**Post date:** [February 5, 2016, 8:50pm UTC](https://forums.knack.com/t/disable-options-in-dropdown-menu/7734/10 "2016-02-05T20:50:15Z")

</div>

Ok thank for sharing.

I can think of two ways to do it.

1. Involves just Javascript, but I need to test that I can access the data easily (I won't do this in you're app but in one of my test apps).

It would involving adding something to your UI - but we'll see if work first.

2. API calls, this gets a little more complicated so hopefully option 1 works.

I will see what I can do and be in touch.

---

<div class="post-metadata">

**Author:** ![BennetSt.L83204](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@BennetSt.L83204](https://forums.knack.com/u/BennetSt.L83204)\
**Post date:** [February 5, 2016, 8:27pm UTC](https://forums.knack.com/t/disable-options-in-dropdown-menu/7734/11 "2016-02-05T20:27:17Z")

</div>

Got it

---

<div class="post-metadata">

**Author:** ![ChrisAgnew79606](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@ChrisAgnew79606](https://forums.knack.com/u/ChrisAgnew79606)\
**Post date:** [February 5, 2016, 8:21pm UTC](https://forums.knack.com/t/disable-options-in-dropdown-menu/7734/12 "2016-02-05T20:21:41Z")

</div>

Just shared with you. Let me know if any direction is needed.

---

<div class="post-metadata">

**Author:** ![BennetSt.L83204](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@BennetSt.L83204](https://forums.knack.com/u/BennetSt.L83204)\
**Post date:** [February 5, 2016, 3:56pm UTC](https://forums.knack.com/t/disable-options-in-dropdown-menu/7734/13 "2016-02-05T15:56:03Z")

</div>

[How to Share](http://helpdesk.knackhq.com/support/solutions/articles/5000522285-how-to-add-a-shared-builder-to-your-knack-app)

email address you can share with is [bennet.knack@gmail.com](mailto:bennet.knack@gmail.com)

---

<div class="post-metadata">

**Author:** ![ChrisAgnew79606](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@ChrisAgnew79606](https://forums.knack.com/u/ChrisAgnew79606)\
**Post date:** [February 5, 2016, 3:44pm UTC](https://forums.knack.com/t/disable-options-in-dropdown-menu/7734/14 "2016-02-05T15:44:56Z")

</div>

Sorry for the delayed response. Yes, I am willing to share my app but also not quite sure how to go about that. If you can point me in the right direction, I am happy to share.

---

<div class="post-metadata">

**Author:** ![BennetSt.L83204](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@BennetSt.L83204](https://forums.knack.com/u/BennetSt.L83204)\
**Post date:** [February 4, 2016, 1:59pm UTC](https://forums.knack.com/t/disable-options-in-dropdown-menu/7734/15 "2016-02-04T13:59:45Z")

</div>

Having a hard time picturing how the DB is set up and how everything works together. Are you willing to share the app so I can take a look?

I pretty sure its possible but what it involves would depend on how its all set up.

---

<div class="post-metadata">

**Author:** ![ChrisAgnew79606](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@ChrisAgnew79606](https://forums.knack.com/u/ChrisAgnew79606)\
**Post date:** [February 4, 2016, 12:17am UTC](https://forums.knack.com/t/disable-options-in-dropdown-menu/7734/16 "2016-02-04T00:17:49Z")

</div>

\*\*There are two separate objects within the same form that contain the values.

---

<div class="post-metadata">

**Author:** ![ChrisAgnew79606](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@ChrisAgnew79606](https://forums.knack.com/u/ChrisAgnew79606)\
**Post date:** [February 4, 2016, 12:16am UTC](https://forums.knack.com/t/disable-options-in-dropdown-menu/7734/17 "2016-02-04T00:16:03Z")

</div>

Thanks for getting back to me Bennet and my apologies for the original confusion. There are two separate objects. The first object is a calendar event, and there is one event each week for 27 weeks. The second object is a drop down menu of players (records) participating in the corresponding week's event. I have 60 users and each user selects a player (record) each week. My goal is to disable all of the players (records) from the current week's drop down menu that were previously selected based off the logged in user.

Hope this helps. Please let me know of any additional questions.

---

<div class="post-metadata">

**Author:** ![BennetSt.L83204](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@BennetSt.L83204](https://forums.knack.com/u/BennetSt.L83204)\
**Post date:** [February 3, 2016, 11:00pm UTC](https://forums.knack.com/t/disable-options-in-dropdown-menu/7734/18 "2016-02-03T23:00:55Z")

</div>

Question:

Could you clarify "Previous Selections"? - Are there multiple fields within the same form that contain the values? Or are they between different records.
