Hi all,
Yet another blogpost about jQuery. This time we are going to hide some values in a dropdown field. This is not a way to create a cascaded dropdown, but it could be helpful if you want the users to be able to not select something when a specific rule is met.
Example: you cannot set a status to reviewed if you are not a manager.
Code
<script language="javascript" type="text/javascript"> $(document).ready( function() { var dropdown = $(":input[title='DropdownField']"); dropdown.find("option[value=’value 1’]").remove(); dropdown.find("option[value='value 2']").remove(); dropdown.find("option[value='value 3']").remove(); }); </script>
So, what does this do ?
When our page is loaded, we create a variable and fill it up with the dropdown field. Next we can remove all options in there.
This is exacly what I was looking for. Thank you very much!!
This code doesn’t work for me
Yogendra,
What is going wrong ? Can you send your code to me ? (marijn.somers @ balestra.be – without spaces)
Hi Marijn,
I checked it once again and found that the Above code is working for a normal dropdown (a choice column) but not working for a lookup column.
I have a dropdown which is taking value from another list as a lookup.
can you guide me, how it will work.
Yogendra, here is the code how to hide items from a lookup field:
http://www.balestra.be/2013/03/hide-dropdown-items-from-lookup-fields-in-sharepoint-via-jquery.html
Thank you so much.
Hi Marijin, How do I add back the drop down values if needed…
What harm will Removing Old Dropdown Fields From SharePoint actually do, when you have thousands of lines of data in a library with these field names?
they will stay there with that value, until you edit/open the item, then it refreshes.