开发者

checkboxlist check functionality

I have a CheckBoxList id="cblFiles" and a CheckBox id="Checkbox1".

I have added checkAll functionality to the CheckBoxList. And now what I need to check is if any CheckBox in the CheckBoxList is unchecked "Checkbox1" should be unchecked.

Following code doesn't work for me

function SelectNoneCheckboxes() {
    var elm = document.getElementById("<%=cblFiles.ClientID %>"); 
    for (i = 0; i < elm.childNodes.length; i++) {
        if (elm.childNodes[i].checked == false) {
            document.getElementById("<%=Checkbox1.ClientID %>").checked = false;
        }
    }
}

code for the checkAll Functionality

function SelectAllCheckboxes(spanChk) {

            var oItem = spanChk.children;
            var theBox = (spanChk.type == "checkbox") ?
        spanChk : spanChk.children.item[0];
            xState = theBox.checked;
            elm = theBox.form.elements;

 开发者_JAVA技巧           for (i = 0; i < elm.length; i++)
                if (elm[i].type == "checkbox" &&
              elm[i].id != theBox.id) {


                if (elm[i].checked != xState)
                    elm[i].click();


            }
        }


Try this

function SelectNoneCheckboxes() {
        var elm = document.getElementById("<%=cblFiles.ClientID %>");
        var checkBoxes = elm.getElementsByTagName("input");
        for (i = 0; i < checkBoxes.length; i++) {
            if (checkBoxes[i].checked == false) {
                document.getElementById("<%=Checkbox1.ClientID %>").checked = false;
            }
        }
    }

Server code

protected void Page_PreRender(object sender, EventArgs e)
    {
        CheckBox1.Attributes["onClick"] = "CheckAll(this.checked);";
    }

Script

 function CheckAll(value) {
        var checkBoxList = document.getElementById("<%= CheckBoxList1.ClientID %>");
        if (value !== true) return;
        var checkBoxes = checkBoxList.getElementsByTagName("input");
        for (i = 0; i < checkBoxes.length; i++) {
            checkBoxes[i].checked = true;
            }
        }


function SelectNoneCheckboxes() {
                var elm = document.getElementById("<%=cblFiles.ClientID %>");
                var checkBoxes = elm.getElementsByTagName("input");
                for (i = 0; i < checkBoxes.length; i++) {
                    if (checkBoxes[i].checked == false) {
                        document.getElementById("<%=Checkbox1.ClientID %>").checked = false;
                        break;
                    }
                    else {
                        document.getElementById("<%=Checkbox1.ClientID %>").checked = true;
                    }
                }
            }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜