Dear jacob_kochi,
actually this is a php forum, hard to ask for javascript help. You'd better to ask in the approriate javascript forum. But maybe this script will help you a little.
The script will do check to all form elements (validate form) and at least one of the checkbox in the form elements should be checked. Please extract the function for suit your need.
<script language="JavaScript">
<!--
function validateForm (form) {
for (var e = 0; e < form.elements.length; e++) {
var el = form.elements[e];
if (el.type == 'text' || el.type == 'textarea' ||
el.type == 'password' || el.type == 'file' ) {
if (el.value == '') {
alert('Please fill out the text field ' + el.name);
el.focus();
return false;
}
}
else if (el.type.indexOf('select') != -1) {
if (el.selectedIndex == -1) {
alert('Please select a value of the select field ' + el.name);
el.focus();
return false;
}
}
else if (el.type == 'radio') {
var group = form[el.name];
var checked = false;
if (!group.length)
checked = el.checked;
else
for (var r = 0; r < group.length; r++)
if ((checked = group[r].checked))
break;
if (!checked) {
alert('Please check one of the radio buttons ' + el.name);
el.focus();
return false;
}
}
else if (el.type == 'checkbox') {
var group = form[el.name];
if (group.length) {
var checked = false;
for (var r = 0; r < group.length; r++)
if ((checked = group[r].checked))
break;
if (!checked) {
alert('Please check one of the checkboxes ' + el.name);
el.focus();
return false;
}
}
}
}
return true;
}
// -->
</script>
.:: Baronmask ::.