| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 704 人关注过本帖
标题:想在前台判断字段是否为空?不提示错误?
取消只看楼主 加入收藏
fengmnll
Rank: 1
等 级:新手上路
帖 子:79
专家分:3
注 册:2008-11-6
结帖率:85.71%
收藏
 问题点数:0 回复次数:1 
想在前台判断字段是否为空?不提示错误?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script language="JavaScript" type="text/javascript" src="../js/function.js"></script>
<script  language="javascript">
function check()
            if  document.myform.student_id.value == ""  then
                  window.alert('请输入名称!!');
                  document.myform.student_id.focus();
                   return  false
            else if
            End if
            if  document.myform.student_name.value == ""  then
                  window.alert('请输入名称!!');
                  document.myform.student_name.focus();
                   return  false
            else if
            End if
            if  document.myform.sex.value == ""  then
                  window.alert('请输入名称!!');
                  document.myform.sex.focus();
                   return  false
            else if
            End if
            return true
       End function     
</script>
</head>

<body>
<table width="45%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30" colspan="2"><div align="center"><strong>添加学生信息</strong></div></td>
  </tr>
<form action="save.asp" method="post" name="" >
  <tr>
    <td width="16%" height="30"><div align="center">姓名:</div></td>
    <td width="84%" height="30"><input name="student_name" type="text" ></td>
  </tr>
  <tr>
    <td height="30"><div align="center" >性别:</div></td>
    <td height="30"><input name="sex" type="text" ></td>
  </tr>
  <tr>
    <td height="30"><div align="center" >年龄:</div></td>
    <td height="30"><input name="age" type="text" v></td>
  </tr>
  <tr>
    <td height="30"><div align="center">入校时间:</div></td>
    <td height="30"><input name="in_time" type="text" ></td>
  </tr>
  <tr>
    <td height="30"><div align="center">专业:</div></td>
    <td height="30"><input name="major" type="text" ></td>
  </tr>
  <tr>
    <td height="30"><div align="center">籍贯:</div></td>
    <td height="30"><input name="homeplace" type="text" ></td>
  </tr>
  <tr>
    <td height="30" colspan="2"><div align="center">
      <input type="submit" name="Submit" value="提交">
      <input type="reset" name="Submit2" value="重置">
    </div>
    </td>
  </tr>
  </form>
</table>
</body>
</html>
谢谢大家,麻烦大家看看
搜索更多相关主题的帖子: 字段 前台 判断 提示 
2010-05-19 14:54
fengmnll
Rank: 1
等 级:新手上路
帖 子:79
专家分:3
注 册:2008-11-6
收藏
得分:0 
回复 2楼 gupiao175
你好,谢谢.不知道能不能帮我在看这个文件
<!--#include file="conn.asp" -->
<%
      dim  sql,student_id,student_name,sex,in_time,homeplace,major
      student_id=Trim(Request.Form("student_id"))
      student_name=Trim(Request.Form("student_name"))
      sex=Trim(Request.Form("sex"))
      age=Trim(Request.Form("age"))
      in_time=Trim(Request.Form("in_time"))
      homeplace=Trim(Request.Form("homeplace"))
      major=Trim(Request.Form("major"))
      set rs=Server.CreateObject("ADODB.Recordset")
      sql="select * from student where student_name='"&student_name&"'"
      rs.open sql,conn,1,3
      if not rs.eof  then
             response.Write"<script> alert('此学生已存在.');history.back(-1);</script>"
                          response.End
     else
            'set rs=nothing
            rs.addnew
            rs("student_name")=student_name
            rs("sex")=sex
            rs("in_time")=in_time
            rs("homeplace")=homeplace
            rs("major")=major
            rs.update
            rs.close
            set rs=nothing

  end if

  'response.Write"<script language=javascript>{window.alert('记录添加成功!');window.location.href=student.asp';}            
    response.write "<script language=jscript>alert(记录添加成功!');history.back(-1)</script>"
     response.Redirect("add_student.asp")
     response.End()
  
%>
整个页面没有跳转?不知道是怎么回事呢?
2010-05-19 19:48
快速回复:想在前台判断字段是否为空?不提示错误?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036299 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved