0

In a SharePoint 2016 list, I have a choice column (appropriately named 'Choice') where I would like to hide certain values in NewForm.aspx.

  • Choice 1
  • Choice 2
  • Choice 3

(I'm trying to hide Choice 2.)

I've got jQuery saved in the Site Assets document library on this same site, and the following script (called "HideChoices.js")

<script src="../SiteAssets/jQuery/jquery-3.3.1.min.js">
$(document).ready(function() {
    var dropdown = $(":input[title='Choice']");
    dropdown.find("option[value='Choice 2']").remove();
});
</script>

I added a link to HideChoices.js to the main web part on NewForm.aspx, but it breaks and I'm not really sure where I'm going wrong.

  • What's the error that you get? – Damjan Tomic Jun 19 '18 at 22:24
  • The page's formatting is broken initially, then trying to click on the New Item link (to access NewPage.aspx) freezes at "Working on it..." – Eric D. Jun 20 '18 at 13:56
0

You only need to put the following scripts to HideChoices.js file and upload this file to Site Assets document library -> jQuery folder.

$(document).ready( function() {
  var dropdown = $(":input[title='Choice']");
  dropdown.find("option[value='Choice 2']").remove();
});

Then, edit the main web part on NewForm.aspx. Go to Miscellaneous -> JS Link. Add the following property into the JS Link textbox.

~site/SiteAssets/jQuery/jquery-3.3.1.min.js|~site/SiteAssets/jQuery/HideChoices.js 

Note:

The format of JSLink proiperty is “~site/<library>/<file>”. Change the value in “<>”.

For example: If you uploaded the JavaScript file custom.js into the Site Assets library, the value for the JSLink property can be "~site/SiteAssets/custom.js".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.