Hide dropdown values from choice fields in SharePoint via jQuery

May 11th, 2011 | Posted by Marijn in jquery / javascript | sharepoint

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.

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

8 Responses



Leave a Reply

%d bloggers like this: