下面的代码放在有表单的那个文件里
<script language=javascript>
function check_user_exists(form){
username=form.username.value;
if (username==null||username==''){
alert("请您输入用户名");
return false;
}
infoBoard=document.getElementById("checkInfo");
infoBoard.innerText='查询中...';
myurl="/admin/admin_userlogin/CheckUser.asp?username="+username;
retCode=openUrl(myurl);
switch(retCode){
case "-2":
infoBoard.innerHTML='<font color=red>抱歉</font>,查询失败';break;
case "0":
infoBoard.innerHTML='<font color=red>恭喜</font>,'+username+'可以使用';break;
case "1":
infoBoard.innerHTML='<font color=red>抱歉</font>,用户名'+username+'已被使用';
}
return;
}
function openUrl(url){
var objxml=new ActiveXObject("Microsoft.XMLHttp")
objxml.open("GET",url,false);
objxml.send();
retInfo=objxml.responseText;
if (objxml.status=="200"){
return retInfo;
}
else{
return "-2";
}
}
</script>
下面这段代码放在检测按钮需要放的位置上
<span id="checkInfo"></span><br><input type=button id="checkInfo" name=checkuser value="检测用户名是否被占用" onClick="check_user_exists(this.form);">
处理文件“如CheckUser.asp”
<!--#include file="../inc/Conn.asp"-->
<%
'username=Request("username")
'Set rs = Server.CreateObject ("ADODB.Recordset")
'sql="select username from [user] where UserName='"&username&"'"
'rs.Open sql,conn,1,1
'if not rs.eof then
'response.write 1
'else
' response.write 0
'end if
'
'rs.close
username=Request("username")
Set rs = Server.CreateObject ("ADODB.Recordset")
sql="select count(username) as num from [user] where UserName='"&username&"'"
rs.Open sql,conn,1,1
if num=1 then
response.write 0
else
response.write 1
end if
rs.close
%>