28 October 2011

validate checkbox list using javascript

function valid()
{
var chkBoxList = document.getElementById('CheckBoxList11');
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: