locked
How to hide a SharePoint Choice Field where display choice is checkbox RRS feed

  • Question

  • Hello all,

    I have a SharePoint choice field called "Operating Systems" and the Display choice is "Checkboxes (allow multiple selections)".

    I need to hied this column on a page load. I tried multiple ways using JavaScript

    getTagFromIdentifierAndTitle("input", "", "Operating Systems");

    getTagFromIdentifierAndTitle("checkbox", "", "Operating Systems"); 

    and none of them are working. Can someone help me how can i make it happen?


    Tuesday, March 6, 2012 6:40 AM

Answers

  • OKAY!!! 

    i found how :-). After long research, the solution is simple. All you have to do is to assign an ID to the Label tag.

    and then to hide 

    ctrl = document.getElementById("nobr1");
    ctrl.parentNode.parentNode.parentNode.style.display="none";

    Thanks to everyone!

    • Marked as answer by Kiran Ivaturi Wednesday, March 7, 2012 10:26 PM
    Wednesday, March 7, 2012 10:26 PM

All replies

  • Hi Kiran,

    Here is the code that I have always used to hide columns.  Didn't have time to test it on a checkbox field, but it is worth a shot.  Also, are you wanting to do this on the DispForm or the EditForm?  Either way, just put this code in a CEWP or directly on the page.  Another method would be to use content types to hide the necessary fields.

    <script language="javascript" type="text/javascript">
    
    _spBodyOnLoadFunctionNames.push("hideFields");
    
    function findacontrol(FieldName) {
       var arr = document.getElementsByTagName("!");
       for (var i=0;i < arr.length; i++ )
       {
          if (arr[i].innerHTML.indexOf(FieldName) > 0) {
             return arr[i];
          }
       }
    }
    
    function hideFields() {
       var control = findacontrol("Field Name Here");
       control.parentNode.parentNode.style.display="none";
    }
    
    </script>

    Cheers,

    Jonathan


    • Edited by JonDeco Tuesday, March 6, 2012 8:40 PM
    Tuesday, March 6, 2012 8:39 PM
  • Thanks for your reply Jonathan!

    document.getElementsByTagName("!"); never worked with "Custom List Form", always returns null.

    reason being "!" is a special mark in the HTML, not really a HTML tag. I tried the above solution before I raised this question to the Forum. It never worked :-(.

    Thanks

    Kiran.

    Tuesday, March 6, 2012 9:10 PM
  •  

    Hi,

    If you want to hide the “Operating Systems” column in NewForm.aspx and EditForm.aspx, you can add a Content Editor Web Part and use the code below.

    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>

    <script type="text/javascript">

    $(document).ready(function(){

      $('.ms-RadioText').closest("table").closest("tr").hide();

    });

    </script>

    And if you need to hide the column in DispForm.aspx, please use the code below.

    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>

    <script type="text/javascript">

    $(document).ready(function(){

      $('#SPFieldMultiChoice').closest("tr").hide();

    });

    </script>

    If anything unclear, please feel free to ask.

    Thanks.


    Emir Liu

    TechNet Community Support

    Wednesday, March 7, 2012 5:41 AM
  • OKAY!!! 

    i found how :-). After long research, the solution is simple. All you have to do is to assign an ID to the Label tag.

    and then to hide 

    ctrl = document.getElementById("nobr1");
    ctrl.parentNode.parentNode.parentNode.style.display="none";

    Thanks to everyone!

    • Marked as answer by Kiran Ivaturi Wednesday, March 7, 2012 10:26 PM
    Wednesday, March 7, 2012 10:26 PM
  • Kiran

    would you mind pasting the code in its entirety?

    thanks

    Saturday, June 8, 2013 7:24 PM
  • Looks Good. What tool are you using to do this ?

    How do you edit the Tag Properties for the list item ?

    Thanks,

    Douglas

    Sunday, November 9, 2014 2:09 AM