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.

2
  • What's the error that you get? Commented Jun 19, 2018 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..." Commented Jun 20, 2018 at 13:56

1 Answer 1

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 and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.