jQuery for Hiding SharePoint Columns
in Getting Started
•
4 years ago
Hi all
I'm new to jQuery, but I've added one to a SharePoint List so hide and show specific columns based on criteria. For example, I have a Choice drop down where users can select either 'US Dollars' or 'Pounds Sterling'. If they choose US Dollars, then a text box (which was hidden) now appears so they can enter in a currency in Dollars.. and vice versa if they select Pounds Sterling.
The query works great when a new item is created in the list, however if you then go back into the item later to edit it, the query no longer runs. Ideally, I want the query to work when a new item is created, but ALSO at anytime a user goes in to edit the item. Is this possible?
<script src="https://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
//Hide columns by default
$('nobr:contains("5Admin_ApprovedAmt USD")').closest('tr').hide();
$('nobr:contains("5Admin_ApprovedAmt GBP")').closest('tr').hide();
//Show/hide columns based on Drop Down Selection
$("select[title='Approved Currency']").change(function() {
if ($("select[title='Approved Currency']").val() != "GBP")
{
$('nobr:contains("5Admin_ApprovedAmt USD")').closest('tr').hide();
$('nobr:contains("5Admin_ApprovedAmt GBP")').closest('tr').show();
}
else
{
$('nobr:contains("5Admin_ApprovedAmt GBP")').closest('tr').hide();
$('nobr:contains("5Admin_ApprovedAmt USD")').closest('tr').show();
}
});
});
</script>
Thanks
Mike
1