Disable or enable Submit button on Checkbox checked event

此生再无相见时 提交于 2019-11-30 10:09:04
$(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.

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 instruction swapped with the else instruction and in the button html markup add disabled="disabled"

may help someone

Jquery:

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

});

... it works for me ...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!