var radios = document.offerForm.need_bond;
var hasChecked = false;
for (var i = 0; i < radios.length; i++) {
if (radios[i].checked) {
hasChecked = true;
break;
}
}
if (!hasChecked) {
//...
}
Thanks for the reply. This works great so i need to move onto the next logical step, how do i check multiple sets on the same form? Below is my code, I tried doing this with just 2 group but the form is submitted regardless of the state of the 2 group of radio elements.
for (i = 0; i < need_bond.length; i++)
{
if (need_bond[i].checked)
{
hasChecked = true;
break;
}
}
if (hasChecked == false)
{
alert('Need bond hasn\'t been checked 1');
return false;
}
else {
for (i = 0; i < need_a_bond.length; i++)
{
if (need_a_bond[i].checked)
{
hasChecked = true;
break;
}
}
if (hasChecked == false)
{
alert('Need a bond hasn\'t been checked 2');
return false;
}
}
return true;
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
function checkBoxes()
{
var allInputs = document.getElementsByTagName('input').length;
var j = 0;
for (i = 0; i <= allInputs; i++)
{
element = document.offerForm[i];
if (element.type == 'radio')
{
if (element.checked == true)
{
j = j + 1;
}
}
}
if (j != 6)
{
alert('All radio buttons has to be checked' +
' before the form can be submitted.');
return false;
}
return true;
}
It works perfectly at the moment.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering