I have a SharePoint 2013 list, and I want to hide certain columns based on a users selection from a drop down list in another column in the same list. Anyone help?
1 Answer
you can do that using the below Sample jquery script
when the dropdown selection changed, the columns visibility change
replace "col1 and "col2" with you columns
and the "dropdown column name" with your dropdown column , and of course
dropdown option 1 & dropdown option 2 with the selection values
<script src="http://code.jquery.com/jquery-1.7.2.min.js" type=text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
// col1 is hidden by default , col2 is visible
$('nobr:contains("col1")').closest('tr').hide();
// Show/hide columns based on Drop Down Selection
// hide col2 and show col1 when selecting "dropdown option 1"
$("select[title='dropdown column name']").change(function() {
if ($("select[title='dropdown column name']").val() == "dropdown option 1") {
$('nobr:contains("col2")').closest('tr').hide();
$('nobr:contains("col1")').closest('tr').show();
}
// hide col1 and show col2 when selecting "dropdown option 2"
else if($("select[title='dropdown column name']").val() == "dropdown option 2"){
$('nobr:contains("col1")').closest('tr').hide();
$('nobr:contains("col2")').closest('tr').show();
}
});
});
</script>