1
votes

For one of the lists, I have to hide column Project (single line of text) based on the choice column 'Customer' drop down selection. I have two values in customer drop down: Customer W Project and Customer WO Project. If the user selects Customer W Project, I want to hide Project column field on the new item click form. Below is the code I am using, please let me know if anything is wrong: Also, I am working on SharePoint 2016 online/office 365.

Any help will be greatly appreciated. Thanks.

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js></script><script src="/sites/lcpatest/Style%20Library/sputility.js"></script>
<script> $(document).ready(function(){
var customer = SPUtility.GetSPField('Customer');var HideOrShowOthersField=function(){var customerValue = customer.GetValue();
 if(customerValue=='Customer W Project'){SPUtility.GetSPField('Project').Hide();
 }else {SPUtility.GetSPField('Project').Show();}};HideOrShowOthersField();
 $(customer.Dropdown).on('change',HideOrShowOthersField);});</script>
1

1 Answers

0
votes

Your jQuery library is so old. Below code works based on my testing.

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="/sites/Developer/SiteAssets/sputility.js"></script>
    <script>
        $(document).ready(function () {
            var customer = SPUtility.GetSPField('Customer');
            var HideOrShowOthersField = function () {
                var customerValue = customer.GetValue();
                if (customerValue == 'Customer W Project') {
                    SPUtility.GetSPField('Project').Hide();
                }
                else {
                    SPUtility.GetSPField('Project').Show();
                }
            };
            HideOrShowOthersField();
            $(customer.Dropdown).on('change', HideOrShowOthersField);
        });
    </script>