Question

I am using this script Hide/Show field on list form based on value from another field and I can get it to work for one item but I have three to hide based on a choice field and it is not working. I really could use some help!!

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"/>
<script src="https://share.philips.com/sites/STS020170908232517/warboard/SiteAssets/sputility.js"/>
<script>
 $(document).ready(function () 
{ // Get a the choice field 
var choiceField = SPUtility.GetSPField('Status');
// Hide the target fields in form load
SPUtility.GetSPField('Compeling Event').Hide();
SPUtility.GetSPField('Final PO Signatory').Hide();
// create a function to show or hide a field based on the selected choice   Field value 
var ShowHideField = function() { 
var selectedFieldValue = choiceField.GetValue(); 
// Hide the 'Other Title' field if the selected value is 'Other' 
if(selectedFieldValue != 'Best Case') { 
SPUtility.GetSPField('Compeling Event').Hide();
SPUtility.GetSPField('Final PO Signatory').Hide();  
} 
else { 
SPUtility.GetSPField('Compeling Event').Show();
SPUtility.GetSPField('Final PO Signatory').Show(); 
} }; 
// attach the function to choice field 
$(choiceField.Dropdown).on('change', ShowHideField); });
</script>
Was it helpful?

Solution

Tested the code you provided, it works in my side:

    <script src="https://code.jquery.com/jquery-1.12.4.js" type="text/javascript"></script>
<script src="http://sp/sites/teams/SiteAssets/sputility.js" type="text/javascript"></script>
<script type="text/javascript">
 $(document).ready(function () 
{ // Get a the choice field 
var choiceField = SPUtility.GetSPField('Status');
// Hide the target fields in form load
SPUtility.GetSPField('Compeling Event').Hide();
SPUtility.GetSPField('Final PO Signatory').Hide();
// create a function to show or hide a field based on the selected choice   Field value 
var ShowHideField = function() { 
var selectedFieldValue = choiceField.GetValue(); 
// Hide the 'Other Title' field if the selected value is 'Other' 
if(selectedFieldValue != 'Best Case') { 
SPUtility.GetSPField('Compeling Event').Hide();
SPUtility.GetSPField('Final PO Signatory').Hide();  
} 
else { 
SPUtility.GetSPField('Compeling Event').Show();
SPUtility.GetSPField('Final PO Signatory').Show(); 
} }; 
// attach the function to choice field 
$(choiceField.Dropdown).on('change', ShowHideField); });
</script>

Make sure sputility.js loaded in the page and the field name is correct.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top