Hi there JS gurus, please help....
This code works well to validate multiple checkboxes that are all named the same which is what I want. The array of checkboxes is dynamic, sometime there will only be one. In this situation if I check this one checkbox it throws the 'You have not ticked any options....'. I would like checked = true to fire in this situation. Im having a headache of a time getting it to work. your help would be appreciated?
var checked = false;
var field = myForm.selectedDocs;
for(var j = 0; j < field.length; j++)
{
if(field[j].checked == true)
{
checked = true;
break;
}
}
if(!checked)
{
alert("You have not ticked any options. At least one must be selected to proceed!")
return false;
}
This code works well to validate multiple checkboxes that are all named the same which is what I want. The array of checkboxes is dynamic, sometime there will only be one. In this situation if I check this one checkbox it throws the 'You have not ticked any options....'. I would like checked = true to fire in this situation. Im having a headache of a time getting it to work. your help would be appreciated?
var checked = false;
var field = myForm.selectedDocs;
for(var j = 0; j < field.length; j++)
{
if(field[j].checked == true)
{
checked = true;
break;
}
}
if(!checked)
{
alert("You have not ticked any options. At least one must be selected to proceed!")
return false;
}