Abhijit Abhijit - 1 month ago 7
ASP.NET (C#) Question

Check atleast one checkboxlist item is selected in javascript

I want to check if atleast one item in asp:checkbox list is selected or not and if atleast one item is selected in checkboxlist then I want to enable button.

Please help!!!

Answer

Refer the link Validating checkboxList Asp.Net control using javascript for details. Please try:

<script language="javascript" type="text/javascript"> 
function CheckItem(sender, args){     
    var chkControlId = '<%=chkMealPeriod.ClientID%> '    
    var options = document.getElementById(chkControlId).getElementsByTagName('input');    
    var ischecked=false;    
    args.IsValid =false;    
    for(i=0;i<options.length;i++)    
    {        
        var opt = options[i];        
        if(opt.type=="checkbox")        
        {                       
            if(opt.checked)            
            {                
                ischecked= true;                
                args.IsValid = true;                            
            }        
        }     
    }
}