Hiding Sharepoint Survey List fields

4k views Asked by At

I have a survey list. I need to hide a particular question by placing javascript in a content editor webpart. Can anybody give me the proper javascript code to hide the question in the survey list?

2

There are 2 answers

2
Paul Leigh On
document.getElementById('MyQuestionID').style.display = 'none';

Though I'd suggest using JQuery and traversing up the dom from the element you want to hide, to hide the thjat the element is contained within. In which case, load the JQuery JS file and use something like:

$(document).ready(function() {
    $('input[title="MyQuestionTitle"]').parent().parent().css("display","none");    
});
0
Paul Leigh On

The People Picker is a little trickier to pin down due to the way it is rendered in the browser, try something like this

var searchText = RegExp("FieldName=\"[YOUR PEOPLE PICKER NAME]\"", "gi");  
$("td.ms-formbody").each(function() {  
    if(searchText.test($(this).html())) 
    {  
        $(this).find("div[Title='People Picker']").css('display', 'none');
        return false;  
    }  
});