首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

单选按钮验证的有关问题

2012-03-01 
单选按钮验证的问题js部分scripttype text/javascript !--functioncheckform()//验证表单元素是否为

单选按钮验证的问题
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;
}

热点排行