Saturday, August 9, 2008

Multiple Checkbox Validation using Javascript

function ValidateWatchList(formNm,action)
{
var errMsg = "Please select the following item(s):\n\n";
var errNum = 0;
var fldName = "";
var passerr = 0;

//alert(formNm.delet.length);
if(formNm.delet.checked == false || formNm.delet.checked == true)
{
//alert('if')
if(formNm.delet.checked == false)
{
if( !errNum ) fldName = "delet";
errMsg += ++errNum + ". Select a product to delete.\n";

if(errNum)
{
alert(errMsg);
return false;
}
}
else
{
return true;
}
}
else
{ //alert('else')
var arrlen = formNm.delet.length;
var i;
var txt = "";
for (i = 0; i < arrlen; i++) {
if (formNm.delet[i].checked) {
txt = txt + formNm.delet[i].value + " ";
}
}
if(txt == "")
{
if( !errNum ) fldName = "delet";
errMsg += ++errNum + ". Select a product to delete.\n";
}
}
if(errNum)
{
alert(errMsg);
return false;
}

return true;

}

No comments:

Popular Posts