Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable or enable Submit button on Checkbox checked event

I want something like this but with a slight change. I want a Button to be enabled or disabled on Checkbox checked event, i.e. when checkbox is checked then and then only button should be enabled otherwise it is disabled. This should be done using jQuery Code not JavaScript.

As this is MVC form so there is no Form ID.

like image 843
Ashes Avatar asked May 27 '11 08:05

Ashes


People also ask

How enable submit button when CheckBox is checked in asp net?

Have your Button disabled by default. Then, using the CheckedChanged event of your CheckBox, check the Checked property. If True, then enable your Button.

How do you disable enable a button with a CheckBox if checked in angular?

We will use the Angular JS directive named ng-disabled to disable the button by unchecking the box. Please refer to AngularJS ng-disabled Directive. The ng-disabled directive is used to enable or disable the HTML elements.

How do I enable a submit button?

Approach: To enable or disable the form submit button, we use the below code snippet. $('#enabled'). click(function () { if ($('#submit-button').is(':disabled')) { $('#submit-button'). removeAttr('disabled'); } else { $('#submit-button').


1 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's a live demo.

like image 98
Darin Dimitrov Avatar answered Sep 28 '22 08:09

Darin Dimitrov