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

无法实现检测留言者是否填写了必要信息…该如何处理

2012-02-04 
无法实现检测留言者是否填写了必要信息……请问下面的代码那里出错了,无法实现检测用户是否填写了必要的信息

无法实现检测留言者是否填写了必要信息……
请问下面的代码那里出错了,无法实现检测用户是否填写了必要的信息


……………………………………………………


<table width="100%" height="12" border="0" cellpadding="2" cellspacing="0">
  <tr>
  <td width="100%"><p align="center">
<img border="0" scr="loge.gif" width="400" height="40" alt="留言板"></td>
  </tr>
  <tr>
  <td width="100%" height="6"><p align="center">
  <font color="#8EB4D9">[</font>
  <a href="input.php"><font color="#008000">签写留言</font></a>
  <font color="#8EB4D9">]</font>
  <font color="#8EB4D9">[</font>
  <a href="browse.php"><font color="#008000">查看留言</font></a>
  <font color="#8EB4D9">]</font>
  <font color="#8EB4D9">[</font>
  <a href="search_input.php"><font color="#008000">搜索留言</font></a>
  <font color="#8EB4D9">]</font>
  <font color="#8EB4D9">[</font>
  <a href="login.php"><font color="#008000">版主管理</font></a>
  <font color="#8EB4D9">]</font>
  <font color="#8EB4D9">[</font>
  <a href="index.htm"><font color="#008000">返回首页</font></a>
  <font color="#8EB4D9">]</font>
  </td></tr>
</table>
<html>
<script language="javascript">
 function checkmessage()
 {
if (msgform.username.value=="")
{
alert("用户名不能为空!");
msgform.username.focus();
return false;
}
if (msgform.password.value=="");
{
alert("用户密码不能为空!");
msgform.password.focus();
return false;
}
if (msgform.E-mail.value=="");
{
alert("E-mail不能为空!");
msgform.E-mail.focus();
return false;
}
else if (msgform.E-mail.value.charat(0)=="." ||
msgform.E-mail.value.charat(0)=="@" ||
msgform.E-mail.value.indexof('@',0) == -1 ||
msgform.E-mail.value.indexof('.',0) == -1 ||
msgform.E-mail.value.lastIndexof("@")==msgform.E-mail.value.length-1 ||
msgform.E-mail.value.lastIndexof(".")==msgform.E-mail.value.length-1 ||)
{
alert("E-mail的格式不对!");
msgform.E-mail.select();
return false;
}
if (msgform.title.value=="")
{
alert("留言标题不能为空!");
msgform.title.focus();
return false;
}
if (msgform.content.value=="")
{
alert("留言内容不能为空!");
msgform.content.focus();
return false;
}

}
</script>
<body bgcolor="#ffffff" text="#000000">
<h1 align=center><font color=blue>在这里留言</font></h1>
<form name="msgform" method="post" action="write.php" enctype="multipart/form-data" onSubmit="return checkmessage()">
<table width="64%" border="0" cellspacing="1" cellpadding="3" bgcolor="#66ccff" align="center">
<tr>
  <td width="48%">用户:
  <input type="text" name="username">
</td>
<td width="52%">密码:


<input type="password" name="password">
</td>
</tr>
<tr>
  <td width="48%">性别:
  <select name="select" size="1">
  <option>秘密</option>
  <option>帅哥</option>
  <option>霉女</option>
</select>
</td>
<td width="52%">E-mail:
<input type="text" name="E-mail" maxlength="50">  
</td>
</tr>
<tr>
<td colspan="2">留言:
<input type="checkbox" name="checkbox" value="Y">
隐藏IP</td>
</tr>
<tr>
<td colspan="2">标题:
<input type="text" name="title" size="60" maxlength="50"></td>
</tr>
<tr>
  <td colspan="2">
  <textarea type="text" name="content" rows="10" cols="100"></textarea>
</td>
</tr>
<tr>
  <td>
  <div align="right">
  <input type="submit" name="Submit" value="提交">
</div>
</td>
  <td>
<input type="reset" name="Rewrite" value="重写">
</td>
</tr>
</table>
</form>
</body>
</html>


帮帮忙看一下,我正在学PHP,以前没学过javascript,阿海先谢谢了

[解决办法]

HTML code
<html> <script language="javascript"> function checkmessage() {     var f = document.msgform;    var re = new RegExp();    var s;    s = f.username.value;    s = s.replace(/(^\s+)|(\s+$)/g, "");    if(s == ""){         alert("用户名不能为空!");        f.username.focus();         return false;     }    s = f.password.value;    s = s.replace(/(^\s+)|(\s+$)/g, "");    if(s == ""){        alert("用户密码不能为空!");        f.password.focus();         return false;     }    s = f.email.value;    s = s.replace(/(^\s+)|(\s+$)/g, "");    if (s == ""){        alert("E-mail不能为空!");         f.email.focus();         return false;     }     else{        if(s.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){            alert("E-mail的格式不对!");             f.email.select();             return false;        }    }    s = f.title.value;    s = s.replace(/(^\s+)|(\s+$)/g, "");    if (s == ""){        alert("留言标题不能为空!");         f.title.focus();         return false;     }    s = f.content.value;    s = s.replace(/(^\s+)|(\s+$)/g, "");    if (s == ""){         alert("留言内容不能为空!");        f.content.focus();         return false;     }     return true;} </script> <body bgcolor="#ffffff" text="#000000"> <h1 align=center> <font color=blue>在这里留言 </font> </h1> <form name="msgform" method="post" action="write.php" onSubmit="return checkmessage()"> <table width="64%" border="0" cellspacing="1" cellpadding="3" bgcolor="#66ccff" align="center"> <tr>       <td width="48%">用户:          <input type="text" name="username">   </td>   <td width="52%">密码:   <input type="password" name="password">   </td> </tr> <tr>       <td width="48%">性别:       <select name="select" size="1">       <option>秘密 </option>       <option>帅哥 </option>       <option>霉女 </option>   </select>   </td>   <td width="52%">E-mail:   <input type="text" name="email" maxlength="50">     </td> </tr> <tr> <td colspan="2">留言: <input type="checkbox" name="checkbox" value="Y"> 隐藏IP </td> </tr> <tr> <td colspan="2">标题: <input type="text" name="title" size="60" maxlength="50"> </td> </tr> <tr>      <td colspan="2">      <textarea type="text" name="content" rows="10" cols="100"></textarea> </td> </tr> <tr>      <td>      <div align="right">      <input type="Submit" name="Submit" value="提交"> </div> </td>      <td> <input type="reset" name="Rewrite" value="重写"> </td> </tr> </table> </form> </body> </html> 

热点排行