21 March 2012

checkbox list javascript validation

function valid()
    {   
       var chkBoxList = document.getElementById('<%=CheckBoxList11.ClientID %>');
        var chkBoxCount= chkBoxList.getElementsByTagName("input");
        var k=0;
        for(var i=0;i<chkBoxCount.length;i++)
        {
            if(chkBoxCount[i].checked)
            k++;
        }
        if(k==0)
        alert("select any item");
        return false;
    }

No comments: