Search code examples
javascripthtmlcssrazorengine

JavaScript not working on @Html.CheckBoxFor


When textbox is empty checkbox disabled but when texbox filled removed attribute as shown in code: this is work on checkbox but not in razor view engine please anyone help me

@Html.TextBoxFor(model => model.OrganizationName, new { @class = "enableSubmitOnChange" }) 
@Html.CheckBoxFor(model => model.ShowOnReport, new { @disabled = "disabled" })

JavaScript is

   $('input.enableSubmitOnChange').change(function(){
        if($(this).val()!="")
            $(this).parents('form').find('input:checkbox').attr('disabled','');
        else
            $(this).parents('form').find('input:checkbox').attr('disabled','disabled');
    });

Solution

  • You should remove disable attribute. Setting it to an empty string still means it is disabled.

    $(this).parents('form').find('input:checkbox').removeAttr('disabled');