0

I have a choice filed (Radio Button) call Test1 with 2 options, BHCD and Prison, I also have another choice filed (Radio Button) call Test2, with BHDC1, BHDC2, BHDC3 and Prison1 , Prison2, Prison3. What I want is if the users select BHDC then users must select one of the 3 options in BHDC and same for Prison. my below code doesn't seems to work.

if ($("input[id^='Test1'][type='radio']:checked").val() == "BHDC" && $( 'select[id^="Test2"]').val('')) { alert("Please select one of the options: BHDC1 , BHDC2 , BHDC3"); return false; }

0

What you are looking for seems to be a cascading dropdown list. You can refer to the below blogs for more help.

For SharePoint On-Prem or SharePoint Online classic experience:https://www.c-sharpcorner.com/article/cascading-of-lookup-dropdown-fields-on-sharepoint-2013-and-o/

Multilevel Cascading Dropdowns for SharePoint 2013, 2016, and O365 Classic forms

For SharePoint Online modern experience, it may be better to use PowerApps.

0

If you are using SharePoint online list classic New/ Edit Form use below JavaScript code

<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>

<script type="text/javascript">
    $(document).ready(function() {
    
     if ($("input[name^='Test1']:checked").val() == "Prison") {
              $("input[value='Prison1']").prop("checked", true);
              $("input[value='BHDC1']").attr("disabled", true);
              $("input[value='BHDC2']").attr("disabled", true);
              $("input[value='BHDC3']").attr("disabled", true);
              
                $("input[value='Prison1']").attr("disabled", false);
              $("input[value='Prison2']").attr("disabled", false);
              $("input[value='Prison3']").attr("disabled", false);
              
            } else if ($("input[name^='Test1']:checked").val() == "BHCD"){
              $("input[value='BHDC1']").prop("checked", true);
              $("input[value='Prison1']").attr("disabled", true);
              $("input[value='Prison2']").attr("disabled", true);
              $("input[value='Prison3']").attr("disabled", true);
              
                $("input[value='BHDC1']").attr("disabled", false);
              $("input[value='BHDC2']").attr("disabled", false);
              $("input[value='BHDC3']").attr("disabled", false);
            }
    
        $("input[name^='Test1']").change(function() {
           if ($("input[name^='Test1']:checked").val() == "Prison") {
              $("input[value='Prison1']").prop("checked", true);
              $("input[value='BHDC1']").attr("disabled", true);
              $("input[value='BHDC2']").attr("disabled", true);
              $("input[value='BHDC3']").attr("disabled", true);
              
                $("input[value='Prison1']").attr("disabled", false);
              $("input[value='Prison2']").attr("disabled", false);
              $("input[value='Prison3']").attr("disabled", false);
              
            } else if ($("input[name^='Test1']:checked").val() == "BHCD"){
              $("input[value='BHDC1']").prop("checked", true);
              $("input[value='Prison1']").attr("disabled", true);
              $("input[value='Prison2']").attr("disabled", true);
              $("input[value='Prison3']").attr("disabled", true);
              
                $("input[value='BHDC1']").attr("disabled", false);
              $("input[value='BHDC2']").attr("disabled", false);
              $("input[value='BHDC3']").attr("disabled", false);
            }

    });
});
</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.