Disable or enable the submit button in the checkbox

I want something similar, but with a few changes. I want the button to be enabled or disabled in the checkbox of the checkbox, i.e. When the checkbox is checked, then only the button should be enabled, otherwise it will be disabled. This should be done using jQuery code, not JavaScript.

Since this is an MVC form, it means there is no form identifier.

+3
source share
3 answers
$(function() {
    $('#id_of_your_checkbox').click(function() {
        if ($(this).is(':checked')) {
            $('#id_of_your_button').attr('disabled', 'disabled');
        } else {
            $('#id_of_your_button').removeAttr('disabled');
        }
    });
});

And here is a live demonstration .

+20
source

This is old, but worked for me with jquery 1.11

<script>
$(function() {
    $('#checkbox-id').click(function() {
        if ($(this).is(':checked')) {
            $('#button-id').removeAttr('disabled');
        } else {
            $('#button-id').attr('disabled', 'disabled');
        }
    });
});
</script>

the if command is replaced by the else statement and in the html button markup add disabled = "disabled"

can help someone

Jquery:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
+1
$('#checkbox').click(function(){
    if($(this).is(':checked')){
        $('#submitButton').attr("disabled", "true");
    }else {
        $('#submitButton').removeAttr("disabled");
    }

});

... ...

0

All Articles