Using SharePoint Designer 2010, I created a variation of a newform.aspx with certain fields purposely removed.

There is a dropdown select box called category with three items ( red, blue, green). I would like to make "category" pre-selected with the value of green and red and blue un-selectable.

And in turn on the original newform.aspx I would like only Red and Blue to be selectable. Is there a way to do this?


Hi use the following example

Html Code:

<select id="coloroptions">
    <option id="red" value="red">Red</option>
    <option id="blue" value="blue">Blue</option>
    <option id="green" value="green">Green</option>

And here the pure JavaScript without jQuery:

var selectObj = document.getElementById("coloroptions").getElementsByTagName("option");
for (var idx = 0; idx < selectObj.length; idx++) {  
  if (selectObj[idx].value.toLowerCase() == "green") 
    selectObj[idx].disabled = true;

Here the full example: https://jsfiddle.net/38zesd0w/3/

Just make sure that the JavaScript is executed after the dropdownlist is rendered.

  • That sounds awesome. However how do I only let them choose the first two only and not let them choose the third. Nov 6 '15 at 14:45
  • Did u try the example? In my browser it is not possible to select the deactivated option. Nov 7 '15 at 16:05
  • Sebastian, I'm trying: <script type="text/javascript"> //<![CDATA[ $(window).load(function(){ var selectObj = document.getElementById("ff6_1").getElementsByTagName("option"); for (var idx = 0; idx < selectObj.length; idx++) { if (selectObj[idx].value.toLowerCase() == "Safety Alerts") { selectObj[idx].disabled = true; } } });//]]> </script> and it's not working :( What am I doing wrong? Nov 10 '15 at 15:54
  • please refer to my example in the jsfiddle. Does this work? And also pay attention to the string function "toLowerCase()" it means that all string will be made to lower case so no string will match "Safety Alerts". I suggest you use the debugger in your Browser to check the code. Nov 10 '15 at 20:20
  • Thank you Sebastian, I have tried it indeed. I am not a coder, :( How do I remove to lowercase? Thank you for your help. Nov 10 '15 at 21:50

Yes. put a Content Editor web part on the newform.aspx page. And using Jquery.ready function select the Dropdown list box once document is loaded.

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.