hey guys so im trying to check if a checkbox is checked. and if one checkbox is checked a button is enabled if more than 1 it is still disabled; button is disabled by default.

<script type="text/javascript">
    var editbtn = $("#edit_contact");
    editbtn.attr("disabled","disabled");

    $('.contacts input:checkbox').live("click", function()
    {
        if(this.checked.length === 1)
        {
            editbtn.removeAttr("disabled");
        }
        else
        {
            editbtn.attr("disabled","disabled");
        }
    })
</script>

what am i doing wrong?
TIA

jQuery's live function is deprecated. You should use jQuery's ON function, instead.

Also, since you didn't post your html along with this script, can you clarify if all the checkboxes you're working with have an ID of "contacts"? Since, I noticed you used:
$('.contacts input:checkbox')
which would select all checkboxes which are the children of an element with the class "contacts". This is ambiguous, therefore, please clarify what you intended to select. I'm assuming for the sake of this solution, that all your checkboxes have a common class of "contacts" and you were intending to select all of them. With this assumption in mind, the code below should work for you. Notice the changes I made with respect to the code you posted:

<html>
<head>
    <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script type="text/javascript">
        $("#edit_contact").attr("disabled","disabled");

        $('.contacts:checkbox').on("click", function() {
            if(this.checked.length === 1)
            {
                $("#edit_contact").removeAttr("disabled");
            }
            else
            {
                $("#edit_contact").attr("disabled","disabled");
            }
        });
    </script>
</head>

<body>
</body>
</html>

it doesn't seem to be working though. button doesn't get enabed when checkbox clicked

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.