On 30/09/2005 23:00, alu wrote:
[snip]
function checkForIt(){
fr1 = document.forms["form1"];
if(!fr1.ch1.checked && !fr1.ch2.checked && !fr1.ch3.checked){
alert("at least one needs to be checked");
}
}
------------------------
given a form named 'form1'
It would be better, in my opinion, to pass a reference to the form when
calling the function (making a form name/id redundant).
and checkboxes named 'ch1' etc.
If the checkboxes are related, they should have the same name attribute
value.
function isChecked(group) {
for(var i = 0, n = group.length; i < n; ++i) {
if(group[i].checked) {return true;}
}
return false;
}
function validate(form) {
var elements = form.elements;
if(!isChecked(elements['cbox-name'])) {
alert('At least one checkbox should be selected.');
return false;
}
return true;
}
<form action="..." onsubmit="return validate(this);">
Or some variation, thereof.
Mike
--
Michael Winter
Prefix subject with [News] before replying by e-mail.