日期:2014-05-16  浏览次数:20383 次

单选按钮验证的问题
js部分
<script   type= "text/javascript ">
<!--
function   checkform()     //验证表单元素是否为空
{
if   (document.myform.titletype.checked   ==   false)   {
alert( "新闻类别必须选择 ");
document.myform.titletype.focus();
return   false;
}
if   (document.myform.title.value   ==   " ")   {
alert( "新闻标题必须填写 ");
document.myform.title.focus();
return   false;
}
return   true
}
//-->
</script>
表单
<form   name= "myform "   action= "News_Save.asp?cmd=add "   method= "post "   onsubmit= "return   checkform() ">
<table   cellpadding= "0 "   cellspacing= "0 "   width= "650 "   class= "tablestyle ">
<tr> <td   colspan= "2 "   class= "header "> 添加新闻 </td> </tr>
<tr>
<td   width= "10% "> 新闻类别 </td>
<td   width= "90% "> <input   type= "radio "   name= "titletype "   value= "1 "   /> 业界资讯   <input   type= "radio "   name= "titletype "   value= "2 "   /> 华信新闻 </td> </tr>
<tr>
<td> 新闻标题 </td>
<td> <input   type= "text "   name= "title "   maxlength= "50 "   style= "width:500px; "   /> </td> </tr> </table> </form>

新闻标题的验证有效,类别的没用.怎么改?

------解决方案--------------------
if (document.myform.titletype[0].checked == false && document.myform.titletype[1].checked == false) {
alert( "新闻类别必须选择 ");
document.myform.titletype.focus();
return false;
}