ajax验证学号是否在数据库中存在及日期控件
1、html页
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@ page import="java.sql.Connection"%>
<%@ page import="java.sql.Statement"%>
<%@ page import="java.sql.ResultSet"%>
<html>
<head>
<title>注册页面</title>
<script type="text/javascript" src="./js/calendar.js">
</script>
<script type="text/javascript" src="./js/text.js">
</script>
<script>
function getXmlHttpRequest(){
var xmlHttpRequest = null;
if ((typeof XMLHttpRequest) != 'undefined') {
xmlHttpRequest = new XMLHttpRequest();
} else {
xmlHttpRequest = new ActiveXObject('Microsoft.XMLHttp');
}
return xmlHttpRequest;
}
//验证学号是否存在
function checkXH(){
var xhr = getXmlHttpRequest();
var value = document.getElementById("xh").value;
xhr.open("get","CheckUser?xh=" + encodeURI(value),true);
xhr.onreadystatechange = function(){
if(xhr.readyState == 4){
if(xhr.status == 200){
var txt = xhr.responseText;
var obj = document.getElementById('xh_msg');
obj.innerHTML = txt;
}else{
var obj = document.getElementById('xh_msg');
obj.innerHTML = 'system error';
}
}else{
var obj = document.getElementById('xh_msg');
obj.innerHTML = 'checking...';
}
};
xhr.send(null);
}
</script>
</head>
<body>
<form name="registForm" action="regist" method="post" >
<table border="1" align="center">
<tr>
<td colspan="2" id="005">
<center>学生注册</center>
</td>
</tr>
<tr>
<td>学号:</td>
<td>
<input id="xh" type="text" name="xuehao" size="20" />
<span id=xh_msg style="color:red"></span>
</td>
</tr>
<tr>
<td>姓名:</td>
<td><input type="text" name="username" size="20"/></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password" size="21" /></td>
</tr>
<tr>
<td>性别:</td>
<td><input type="radio" name="sex" value="1" size="21" />男 <input
type="radio" name="sex" value="0" size="21" />女</td>
</tr>
<tr>
<td>出生日期:</td>
<td><input type="text" name="birthday" onfocus="calendar()"
size="20" /></td>
</tr>
<tr>
<td>手机号码:</td>
<td><input type="text" id="phone_id" name="stuPhoneNumber"
size="20" onblur="isPhoneNumber()" /></td>
</tr>
<tr>
<td>电子邮件:</td>
<td><input type="text" id="stuEmail_id" name="email" size="20"
onblur="isValidEmail()" /></td>
</tr>
<tr>
<td>生源地:</td>
<td><jsp:include page="liandong1.jsp" /></td>
</tr>
<tr>
<td colspan="2">
<center><input type="submit" value="提交" /> <input
type="button" value="返回" onclick="location.href='/xkxt/index.jsp'" />
</center>
</td>
</tr>
</table>
</form>
</body>
</htm