<html><body>
<input type=radio name=aaa>
<input type=radio name=aaa>
<input type=radio name=aaa>
<input type=radio name=aaa><input type=button value=OK? onclick="alert(getCheckedCheckboxesNum('aaa')>0);">
</body></html>
<script>
/**
* This function is to get the number of checked checkboxe or radio inputs.
* JK 2003-12-08
*/
function getCheckedCheckboxesNum(nameOfCheckBox)
{
var theNum=0;
var theCheckboxInputs=document.getElementsByName(nameOfCheckBox);
for (var i=0;i<theCheckboxInputs.length;i++)
{
if(theCheckboxInputs[i].checked) theNum++;
}
return theNum;
}
</script>

解决方案 »

  1.   

    <form name=test method=post action="#" onsubmit="return checkform(2)"> 
    question1: .......................... 
       <input type="radio" value="1" name="question1">
       <input type="radio" value="2" name="question1">
       <input type="radio" value="3" name="question1">
       <input type="radio" value="4" name="question1"> 
       <input type="radio" value="5" name="question1">
    question2: .......................... 
       <input type="radio" value="1" name="question2">
       <input type="radio" value="2" name="question2">
       <input type="radio" value="3" name="question2">
       <input type="radio" value="4" name="question2">
       <input type="radio" value="5" name="question2">
       <input type="submit">
    </form>
    <script>
    function checkform(len)
    {
    //参数:len,选项数目
    for(var i = 1;i<=len;i++)
    {
        var radios = document.all("question"+i),j;
    for(j=0;j<radios.length;j++)
    {
        if(radios[j].checked)break;
    }
    if(j==radios.length)
    {
        alert("Warning!");
    return false;
        }
    }
    return true;
    }
    </script>
      

  2.   

    /*************************************************************
    名称:adjustreadcheckbox
    功能:判断当前CheckBox是否有指定的个数被选中了
    参数:itemname,表单项的名字
          checkcount,被选中的个数
    返回:true或false
    *************************************************************/
    function adjustreadcheckbox(itemname,checkcount) {
        var thecheckboxcount;
        thecheckboxcount=0;
        var bootobject=document.all.tags("INPUT");
        for (i=0;i<bootobject.length;i++) {
    if (bootobject[i].name==itemname && bootobject[i].checked) {
    thecheckboxcount+=1;
    }
        }
        if (thecheckboxcount!=checkcount) {
    return(false);
        } else {
    return(true);
        }
    }