1

I am noob in coding in JS and SharePoint, I've to check two conditions in NewForm.aspx.

If field, for e.g. "Name" has value "Test", and field "Second Name" has value "Test", then I want field named "Result" to be visible. If values from this two mentioned fields are different, then the field "Result" needs to be hidden.

1
  • Are you using classic experience or modern experience in SharePoint online? All fields are of type "Single line of text'? Commented May 25, 2021 at 14:28

1 Answer 1

0

Try adding below code to your NewForm.aspx using Content Editor or Script Editor web part:

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('nobr:contains("Result")').closest('tr').hide();

        //Show/hide columns based on "Name" column 
        $("input[title^='Name']").change(function () {
            var secondNameVal = $("input[title^='Second Name']").val();

            if ($(this).val() != secondNameVal) {
                $('nobr:contains("Result")').closest('tr').hide();
            } else {
                $('nobr:contains("Result")').closest('tr').show();
            }
        });

        //Show/hide columns based on "Second Name" column 
        $("input[title^='Second Name']").change(function () {
            var nameVal = $("input[title^='Name']").val();
            
            if ($(this).val() != nameVal) {
                $('nobr:contains("Result")').closest('tr').hide();
            } else {
                $('nobr:contains("Result")').closest('tr').show();
            }
        });
    });
</script>

Similar question: Hide a SharePoint list column based on the value of another column

1
  • Hi @analyzer64, did you try this? Is it working for you? Commented May 28, 2021 at 8:30

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.