0

Sorry in advance, I am not that well versed in any coding at all and yet is trying to troubleshoot the following code.

It is able to hide the field at the start but does not show the field when it meets the condition of selecting "Other" from the drop-down.

<script src="//code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
    var selectFieldName="Project Type"; // dropdown field display name
    var otherFieldName="Project Name";// single line of text field display name
    $("input[title='"+otherFieldName+"']").closest("tr").hide();
    $("select[title='"+selectFieldName+"']").change(function(){
        if($(this).val()=="Other"){
            $("input[title='"+otherFieldName+"']").closest("tr").show();
        }else{
            $("input[title='"+otherFieldName+"']").closest("tr").hide();
        }
    });
});
</script>
  • can you also paste html from view source, I suspect your dropdown on change method is not getting called. – Siddharth Vaghasia Jun 12 at 13:01
0

I tested your code in my online environment,it works fine, try to confirm the jQuery library loaded(chrome developer tool->F12). enter image description here

enter image description here

Update:

enter image description here

  • Hi Lee_MSFT, I have my jquery library in my SiteAssets but can't seem to have it load in my Chrome Console. Do you have a guide for me to reference to? – gerd Jun 13 at 7:03
  • Try to save the js file to SiteAssets library and reference it from SiteAssets library. <script src="/sites/lee/SiteAssets/jquery-3.1.0.min.js" type="text/javascript"></script> – Lee_MSFT Jun 13 at 7:09
  • I have did that and only partial of the above code seems to be working. My "Project Name" is currently hidden but changing the "Project Type" does not unhide the field. This should means the js file has no problem loading correct? – gerd Jun 13 at 7:21
  • Yea, Then, you need confirm the element/attribute matches. I upload a screenshot. – Lee_MSFT Jun 13 at 7:28
  • I feel like a dummy right now, I added a mandatory required field and did not realize it will change the title of the field. You have been of great help, @Lee_MSFT – gerd Jun 13 at 7:45

Your Answer

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

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