0

I am having a requirement to hide the list of questions need to hide based on drop down selected in SharePoint 2013 survey list. Can anyone provide solution to achieve the requirement.

Thanks in advance.

  • Can anyone provide insights on this. – user399731 Feb 19 at 6:15
1

You can use JavaScript

For example:

There is a drop down field named "TestChoice" with "Test1" and "Test2" choices. If the "Test1" is selected, hide "test2" text question. If the "Test2" is selected, hide "test1" text question

Here is the demo:

<script src="https://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
    var title ="TestChoice";
    var currentValue = $("select[title='"+ title +"']").val();
    if(currentValue != ""){
        if(currentValue == "Test1"){
            // hide question title
            $(".ms-formlabel:contains('test2')").closest("tr").hide();
            //hide question
            $('input[title="test2"]').closest("tr").hide(); 
            //show 
            $(".ms-formlabel:contains('test1')").closest("tr").show();
            $('input[title="test1"]').closest("tr").show(); 
        } else if(currentValue == "Test2"){
            // hide question title
            $(".ms-formlabel:contains('test1')").closest("tr").hide();
            //hide question
            $('input[title="test1"]').closest("tr").hide(); 
            //show 
            $(".ms-formlabel:contains('test2')").closest("tr").show();
            $('input[title="test2"]').closest("tr").show(); 
        }
    }
   //the change event of the drop down list
    $("select[title='"+ title +"']").change(function(){
        //get the current selected value
        var selected = $(this).val();
        if(selected == "Test1"){
            // hide question title
            $(".ms-formlabel:contains('test2')").closest("tr").hide();
            //hide question
            $('input[title="test2"]').closest("tr").hide(); 
            //show 
            $(".ms-formlabel:contains('test1')").closest("tr").show();
            $('input[title="test1"]').closest("tr").show(); 
        } else if(selected == "Test2"){
            // hide question title
            $(".ms-formlabel:contains('test1')").closest("tr").hide();
            //hide question
            $('input[title="test1"]').closest("tr").hide(); 
            //show 
            $(".ms-formlabel:contains('test2')").closest("tr").show();
            $('input[title="test2"]').closest("tr").show(); 
        }
    });
});
</script>

Update:

To hide/show a Choice field,

First, use F12 to get the id of one of choice value element.

enter image description here

Then, use the script to hide/show this Choice field.

// hide the Choice field     
$("input[id='ctl00_ctl41_g_79ea20a5_47f5_42f7_9ccb_72d2f5ae2047_ctl00_ctl02_ctl04_ctl00_ctl00_ctl04_ctl00_ctl00']").closest('table').hide();
//display the Choice field
$("input[id='ctl00_ctl41_g_79ea20a5_47f5_42f7_9ccb_72d2f5ae2047_ctl00_ctl02_ctl04_ctl00_ctl00_ctl04_ctl00_ctl00']").closest('table').show();

You can use the scripts using a Script Editor web part in the new form and edit form (NewForm.aspx and EditFprm.aspx). Edit the page and add a Script Editor web part, enter the code into it.

  • i would like to hide rating scale fields in survey list. And can you please provide where to add the code snippet in survey list. The rating scale fields are having (line of data) more choices fields. – user399731 Feb 19 at 6:57
  • Check the update – JoannaW_MSFT Feb 19 at 8:22
  • Thank you Joanna, i have followed your steps and get it solved my requirement. Thanks again. – user399731 Feb 21 at 5:14
  • Hi, I am successfully added the code snippet to Survey list new form, but i didn't get the idea to add code snippet to Edit form. Can you please suggest how to add (FYI, the radio button id is differing in new form and in Edit form when use F12). – user399731 Feb 28 at 5:01
  • Hi, i am getting an error when save the survey form , showing "you must specify a value for this required field" even i selected the value before saving the form. kindly provide how to resolve. Thanks in advance. – user399731 Mar 2 at 6:44

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.