1

Looking for help with a javasript to help control fields on a sharepoint custom list form...

Variables are:

F01-a F01-b F01-c F01-d

All questions are drop downs with initial allowable selections of Yes, No or N/A

if F01-a is No then F01-b , F01-c & F01-d either don’t show or are forced to N/A only if question F01-b is No then F01-c & F01-d don’t show or are forced to N/A only if question F01-c is No then F01-d don’t show or is forced to N/A only

  • Have you achieved it? Do you think my answer is helpful? If yes, please "accept" this answer as the best answer. Thanks – JoannaW_MSFT Jul 16 '18 at 1:34
1

You can try following jQuery script.

The function will be trigger if the F01-b , F01-c & F01-d values changes.

<script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript"> 
/**
if F01-a is No 
    then F01-b , F01-c & F01-d either don’t show or are forced to N/A 
only if question F01-b is No 
    then F01-c & F01-d don’t show or are forced to N/A 
only if question F01-c is No then F01-d don’t show or is forced to N/A only
**/
$(document).ready(function(){
    $("select[title^='F01']").change(function(){
        var title = $(this).attr("title");
        var selected = $(this).find("option:selected").text();
        if(title == "F01-a" && selected == "No") {
            //set F01-b , F01-c & F01-d to N/A 
            $("select[title='F01-b']").val("N/A");
            $("select[title='F01-c']").val("N/A");
            $("select[title='F01-d']").val("N/A");
            //hide F01-b , F01-c & F01-d
            $("select[title='F01-b']").hide();
            $("select[title='F01-c']").hide();
            $("select[title='F01-d']").hide();
            // or set F01-b , F01-c & F01-d read-only
            //$("select[title='F01-b']").prop("disabled", "disabled");
            //$("select[title='F01-c']").prop("disabled", "disabled");
            //$("select[title='F01-d']").prop("disabled", "disabled");
        }else if (title == "F01-b" && selected == "No"){
            //set F01-c & F01-d to N/A 
            $("select[title='F01-c']").val("N/A");
            $("select[title='F01-d']").val("N/A");
            //hide F01-c & F01-d
            $("select[title='F01-c']").hide();
            $("select[title='F01-d']").hide();
            // or set F01-c & F01-d read-only
            //$("select[title='F01-c']").prop("disabled", "disabled");
            //$("select[title='F01-d']").prop("disabled", "disabled");
        }else if (title == "F01-c" && selected == "No"){
            //set F01-d to N/A 
            $("select[title='F01-d']").val("N/A");
            //hide F01-d
            $("select[title='F01-d']").hide();
            // or set F01-d read-only
            //$("select[title='F01-d']").prop("disabled", "disabled");
        }else{
            //enable F01-b F01-c & F01-d
            $("select[title='F01-b']").show()
            $("select[title='F01-c']").show();
            $("select[title='F01-d']").show();
            //$("select[title='F01-b']").prop("disabled", "");
            //$("select[title='F01-c']").prop("disabled", "");
            //$("select[title='F01-d']").prop("disabled", "");
        }
    });
});
</script>

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.