0

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" />

Edited by nadiam

3
Contributors
5
Replies
24
Views
3 Years
Discussion Span
Last Post by nadiam
0

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")

Edited by wazz

0

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

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

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

0

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.

0

soultion:

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

    checkboxes.click(function() {
        delbtn.attr("disabled", !checkboxes.is(":checked"));
    });
</script>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.