读书人

如何控制提交的表单项不为空

发布时间: 2012-09-28 00:03:35 作者: rapoo

怎么控制提交的表单项不为空
做了一个表让别人填,有姓名,电话什么的,怎么控制别人提交的信息不能是空的呢?就是说如果他不填名字或者别的什么的就点提交,可以给他返回个对话框提示他没有填入需要的资料,而且也不提交到数据库中,给写个代码吧~~~~~最好要简单实用点的,谢谢了,有分送哦

[解决办法]

HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>Untitled Document</title><script language="javascript">function checkspace(checkstr) {  var str = '';  for(i = 0; i < checkstr.length; i++) {    str = str + ' ';  }  return (str == checkstr);}function checkuser(){  if(checkspace(document.form1.text.value))  {    alert("your name is null");    document.form1.text.focus();    return false;    }    return true    }</script></head><body><form name="form1" action="#" method="post" onsubmit="return checkuser()"><table width="200" border="0" cellspacing="0" cellpadding="0">  <tr>    <td>name:  <input type="text" size="20" name="text" /></td>  </tr>    <tr>    <td><input type="submit" name="submit" value="提交" /></td>  </tr></table></form></body></html> 

读书人网 >ASP

热点推荐