验证用户名是否在数据库中已存在(求助)
本帖最后由 cross_0 于 -12-26 21:21:00 编辑
表单提交的页面index.asp
测试-验证用户名是否重复
functionyanzheng_zhuce(){
vartmpusername=document.zhuce.username.value
if(tmpusername=="")
{
alert("不能为空")
returnfalse
}
else
varurl="check.asp?username="+escape(tmpusername)+"&sid="+Math.random();
xmlHttp.onreadystatechange=processSet;
xmlHttp.open("GET",url,true);
xmlHttp.send();
}
functionprocessSet(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
……
……
……
alert("用户名重复");
}
}
}
}
中间的省略号……部分我就不会写了,另外这个check.asp页面是不是这样写?
dimtmpname
username=request("username")
setrs=server.createobject("adodb.recordset")
sql="select*fromusermsgwhereusername='"&username&"'"
rs.opensql,conn,1,1
ifnotrs.eofthen
tmpname="1"
else
tmpname="0"
endif
%>
我是不是要把tmpname返回到index.asp页面中的省略号部分进行判断,如果是1就alert("用户名重复"),可是这段省略号部分和check.asp的代码我不会写。呵呵。才开始学,请大伙帮帮忙,谢谢了!
分享到:
更多
------解决方案--------------------
varxmlHttp
functioncreateXMLHttp(){
if(window.ActiveXObject){
xmlHttp=newActiveXObject("Microsoft.XMLHTTP");
}
elseif(window.XMLHttpRequest){
xmlHttp=newXMLHttpRequest();
}
}
functionyanzheng_username(){
createXMLHttp();
vartmpusername=document.zhuce.username.value
if(tmpusername=="")
{
document.getElementById("span1").innerHTML="不能为空"
}
else{
varurl="server.asp?username="+tmpusername;
xmlHttp.onreadystatechange=processSet;
xmlHttp.open("GET",url,true);
xmlHttp.send();
}
functionprocessSet(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
if(xmlHttp.responseText=='1'){
document.getElementById("span1").innerHTML="重复数据"
}
if(xmlHttp.responseText=='0'){
document.getElementById("span1").innerHTML="正确"
}
}
}
}
}
functioncheck(f){//returnfalse阻止表单提交
if(f.username.value==''){alert('用户名不能为空!');f.username.focus();returnfalse;}
//有其他验证的继续
if(document.getElementById("span1").innerHTML!="正确"){alert('用户名错误或者正在验证中。。');returnfalse;}
}
楼主去学下基础的dhtml了,这些这么基础的