I have a custom list in SP 2013 where I need to conditionally show/hide fields in the list based on responses to other fields in the list. I'm so close to figuring it out, but it's not been easy. I've completed the following steps: 1) Download jquery and sputility files and posted them to the Style Library 2) In the list, click on New Item > Edit page > Added a content editor webpart > Clicked on Edit Source and entered the code below 3) Directed the code to the jquery and sputility files in the Style Library using the appropriate links
I have the following use case: I have an 'Employee Type' field. If the value = Existing Employee, I want to show the Employee Name and Employee ID fields, while hiding the Candidate Name field. If the value = New Hire/Rehire, I want the Employee Name and Employee ID field to hide, while only the Candidate Name shows.
Below is my code. This code isn't working. Can someone please tell me what I'm doing wrong?
Code:
<script src="/sites/compensationagreements/Code/jquery-3.5.1.min.js"></script>
<script src="/sites/compensationagreements/Code/sputility.min.txt"></script>
<script>
$(document).ready(function(){
alert('jQuery loaded');
var employeetype = SPUtility.GetSPField('Employee Type');
var HideOrShowOthersField=function(){
var employeeValue = employeetype.GetValue();
if(employeeValue=='Existing Employee')
{
SPUtility.GetSPField('Employee Name').Show();
SPUtility.GetSPField('Employee ID').Show();
SPUtility.GetSPField('Candidate Name').Hide();
}
else
{
SPUtility.GetSPField('Employee Name').Hide();
SPUtility.GetSPField('Employee ID').Hide();
SPUtility.GetSPField('Candidate Name').Show();
}
};
HideOrShowOthersField();
$(employeetype.Dropdown).on('change',HideOrShowOthersField);
});
</script>
Thank you!
src
URLs do not reflect that. Try puttingalert('jQuery loaded');
as the very first line inside the$(document).ready()
function.src
url)sputility.min.js
and not.txt
?