<form name="form" method="post" action="" onsubmit="return CheckForm(this)">
<input type="radio" name="fnid" value="" checked>
<input type="radio" name="fnid" value="2">
<input type="radio" name="fnid" value="3">
<input type="radio" name="fnid" value="4">
<input type="radio" name="fnid" value="5">
<input type="radio" name="fnid" value="6">
<input type="radio" name="fnid" value="7">
<input type="radio" name="fnid" value="8">
<input type="submit" name="Submit" value="提交">
</form>
<script language="JavaScript">
function CheckForm(theForm) {
var flag=false; 
for(i=0;i<theForm.fnid.length;i++) { 
if(theForm.fnid[i].checked&&theForm.fnid[i].value=="") { 
flag=true;
break;
}

if(flag) {
alert("请选择分类");
return false;
} else {
return true;
}
}
</script>

解决方案 »

  1.   

    这样写较合理:
    <html>
    <head>
    <script language="JavaScript">
    <!--
    function CheckForm(theForm)
    {
    if(theForm.fnid[0].checked)
    {
    alert("请选择分类"); 
    return false;

    return true;
    }
    // -->
    </script></head><body>
    <form name="form" method="post" action="" onsubmit="return CheckForm(this)">
    <input type="radio" name="fnid" value="" checked>
    <input type="radio" name="fnid" value="2">
    <input type="radio" name="fnid" value="3">
    <input type="radio" name="fnid" value="4">
    <input type="radio" name="fnid" value="5">
    <input type="radio" name="fnid" value="6">
    <input type="radio" name="fnid" value="7">
    <input type="radio" name="fnid" value="8">
    <input type="submit" name="Submit" value="提交">
    </form>
    </body>
    </html>
      

  2.   

    注意:其中form.fnid[i].checked.value的值都是undefined将".value"去掉或改为form.fnid[i].status==true
    如下:
    <script language="JavaScript">
    <!--
    function CheckForm(theForm)
    {
    var flag=true; 
    if(form.fnid[0].status==true)//或用if(theForm.fnid[0].value)

        flag=false; 
    }if(flag==false){alert("请选择分类"); return false;} 
    return true;
    }
    // -->
    </script>
      

  3.   

    注意:其中form.fnid[i].checked.value的值都是undefined将".value"去掉或改为form.fnid[i].status==true
    如下:function CheckForm(theForm)
    {
    var flag=true; 
    if(form.fnid[0].status==true)//或用if(theForm.fnid[0].value)

        flag=false; 
    }if(flag==false){alert("请选择分类"); return false;} 
    return true;
    }
      

  4.   

    注意:上一贴//或用if(theForm.fnid[0].value)有误应改为if(theForm.fnid[0].checked)function CheckForm(theForm)
    {
    var flag=true; 
    if(form.fnid[0].status==true)//或用if(theForm.fnid[0].checked)

        flag=false; 
    }if(flag==false){alert("请选择分类"); return false;} 
    return true;
    }
      

  5.   

    function CheckForm(theForm) {
    var flag=false; 
    for(i=0;i<theForm.fnid.length;i++) { 
    if(theForm.fnid[i].checked&&theForm.fnid[i].value==""&&flag==false) { 
    flag=true;
    }

    if(flag) {
    alert("请选择分类");
    return false;
    } else {
    return true;
    }
    }