I'm hiding certain fields on sharepoint list based on a dropdown value using jquery. if the value in the dropdown is "No" I hide certain fields, otherwise show them. Upon save the values are saved but I click edit I can see the dropdown value is still "No"(which is right) but the fields I hid are showing. How can I prevent this from happening?

<script language="javascript" type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
<script language="javascript" type="text/javascript">
    $( document ).ready(function() {

        var value = $("select[title='The Final Performance Review Conversation Took Place?'] option:selected").text(); 

        if (value == "Yes") { 
            $('nobr:contains("Reassign To")').closest('tr').show(); 
            $('nobr:contains("The Final Performance Review Conversation Took Place?")').closest('tr').show(); 
        else { 
            $('nobr:contains("Reassign To")').closest('tr').hide(); 
            $('nobr:contains("The Final Performance Review Conversation Took Place?")').closest('tr').hide(); 
  • Did you perhaps just add your code when creating a new item (newform) and not while editing the same item which is a different form (editform) ? – Christoffer Jan 7 at 9:31
  • @Christoffer I added it on edit form. it works well for the first until I save then it doesn't preserve the same state when editiing again. – Vusi85 Jan 7 at 9:36
  • If you are hiding the fields using a onchange event, that might be the problem. If you debug your code when opening the edit form, you can see if your code are running. Guess you need to check the selected value on document ready and then hide the fields on the go. Can you share your code? – Christoffer Jan 7 at 9:40
  • yes I'm using an onchange event. Let me try selected option and will get back to you. thanks. – Vusi85 Jan 7 at 9:43
  • 1
    Ah, I think you should hide the fields by default and then check the value. If yes, show, else, hide. And then add an onChange event to hide them if the value changes and are equal to Yes. I prefer hiding, then evaluate/re-evaluate. – Christoffer Jan 7 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.