0

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>
1
  • I think you customized my answer at the mentioned thread so maybe I could help, I would like to know Is there any issue in the above code? it would work to hide and show 2 fields properly! just add your third field as you did for the other 2 fields. to show SPUtility.GetSPField('Third field name').Show(); and to hide SPUtility.GetSPField('Third field name').Hide(); Commented Oct 2, 2017 at 17:52

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.