hey guys so i have an issue with my enable disable function which i just realized a few minutes ago. easier to explain with a screenshot:

08c804f5fc7f9af5f870d8cf5a7cc3fa

so as you can see i have multiple checkboxes. say for example all checkboxes are checked and the delete button is enabled, great! but say i decided i dont want to delete one of the names so i uncheck the checkbox of the name i dont want to delete but then the delete button is disabled because of click. how to modify the code :

<script type="text/javascript">
     var chck = $(".chck"),
                bttn = $("#del_contact");
           bttn.attr("disabled","disabled");
            chck.change(function(){
                if(this.checked){
                    bttn.removeAttr("disabled");
                }else{
                    bttn.attr("disabled","disabled");
                }
            });
</script>

just incase:

<td ><input type='checkbox' name='chck[]' class='chck' value='$sid'>$salut $sname</td>
<input type="submit" id="del_contact" name="del_contact" value="Delete Contact" />

looks like you'll have to check every chkbox on the page. if even one is checked, enable the btn; if none are checked, disable the btn. i think you already have all checkboxes with
var chck = $(".chck")

Count the checked checkboxes. Button is enabled when there are more than zero.

var checkCount = $(".chck:checked").length;

ah. that's what i was thinking. wasn't positive about the syntax.

i did:

 var chkbox = $(".check"),
                button = $("#del_event");
           button.attr("disabled","disabled");
            chkbox.change(function(){
                if($(this.checked).length >= 1 ){
                    button.removeAttr("disabled");
                }else{
                    button.attr("disabled","disabled");
                }
            });

uncheck still happens when 1 out of 2 or more checkboxes unchecked.

soultion:

<script type="text/javascript">
    var checkboxes = $("input[type='checkbox']"),
    delbtn = $("#del_event");

    checkboxes.click(function() {
        delbtn.attr("disabled", !checkboxes.is(":checked"));
    });
</script>
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.