0

Hi this is my code for Check box. I want to

     @Html.CheckBoxFor(m => m.AccountUser.AdminAccess, new
                                       {
                                           data_on_text = "YES",
                                           data_off_text = "NO",
                                           data_on_color = "success",
                                           data_off_color = "danger",
                                           @class = "switchCheckbox",
                                           disabled = "disabled"
                                       })

If I use disabled = "disabled" attr. then it is going to disable whole Check box. I want to disable the No value of Check box. Is there any way to do that.

Ritesh Gore
  • 65
  • 10

2 Answers2

0

You can use onclick event to toggle values of checkbox. But you can disable input only once

 $('#checkbox').on('click', function () {
    if ($(this).prop('checked') === true) {          
    } else {
        $(this).attr('disabled');
    }
});
-1

This is some example code to show you how I would solve this:

            @Html.CheckBoxFor(x=>x.AdminAccess, new
            {
                data_on_text = "YES",
                data_off_text = "NO",
                data_on_color = "success",
                data_off_color = "danger",
                @class = "switchCheckbox",
            })  

            <script>
                $(document).ready(function () {
                    if (!$("#AdminAccess").prop("checked"))
                        $("#AdminAccess").attr("disabled", "disabled");       
                });

            </script>
jwg
  • 5,547
  • 3
  • 43
  • 57