我很难完成这项工作,我是经典的asp和javascript的新手。希望有人能帮助我解决这个问题。我想在main.asp(或结果)上查看response.write,但每次尝试这个时,都会转到pass.asp(在另一页上):(
这是我的代码。 main.asp
=============================================== ===================================
<html>
<head>
<script>
function validate() {
document.getElementById("RegDiv").innerHTML =pass.asp;
}
</script>
<style>
#RegDiv {
color:blue;
}
</style>
</head>
<form name="RegForm" action="reg.asp" method="post" onsubmit="return validate();" />
<table border="1">
<tr><td>First Name:</td>
<td><input type="text" name="fname"></td></tr>
<tr><td>last Name:</td>
<td><input type="text" name="lname"></td></tr>
<tr><td>Email:</td><td><input type="text" name="email"></td>
<tr><td>Username:</td><td><input type="text" name="user"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"></td>
<tr><td colspan="2"> <input type="submit" name="Submit" value="Register"></td></tr>
</table>`</form>
<div id="RegDiv"></div>
</html>
这是我的reg.asp
<%
fname = Request.Form("fname")
lname = Request.Form("lname")
Email = Request.Form("email")
Username = Request.Form("user")
Password = Request.Form("pass")
getSub = Request.Form("Submit")
if getSub="Register" then
Dim goby
goby=0
if len(Email)<= 5 then
goby=1
end if
if Instr(1, Email, "@", 1) <2 then
goby=1
else
if Instr(1, Email, ".", 1) <4 then
goby=1
end if
end if
if fname="" then
response.write("Please provide your first name")
elseif lname="" then
response.write("Please provide your last name")
elseif Email="" then
response.write("Please provide your email")
elseif goby<>0 then
response.write("<span style='#F00'>Please provide a real email address!</span>")
elseif Username
response.write("Please provide your Username")
elseif Password="" then
response.write("Please provide your Password")
else
response.write("Your form was processed successfully")
end if
end if
%>
答案 0 :(得分:0)
你的代码......充其量是奇怪的。你有一个没有返回值的函数返回,什么都不做,你使用提交按钮来检测用户是否正在注册。尝试将代码更改为此,看看是否有帮助。
的变化:
从表单onSubmit
中删除了返回操作添加隐藏值以检查是否注册
为提交类型
设置了javascript设置表单值编辑添加了一个包含的sataement,将main和reg.asp合并为一个页面
修改:将表单操作更改为main.asp
编辑:修正了一些拼写错误
编辑:已更改=至StrComp功能
修改:忘记将ID添加到隐藏值
编辑:为空字符串删除了StrComp,因为它导致了错误
<强> Main.asp 强>
<html>
<head>
<script>
function validate() {
// removed as it will happen and then user will be sent to the next page
// so the user will never see it
//document.getElementById("RegDiv").innerHTML =pass.asp;
document.getElementById('subtype').value = "Register";
}
</script>
<style>
#RegDiv {
color:blue;
}
</style>
</head>
<!--#include virtual="reg.asp"-->
<form name="RegForm" action="main.asp" method="post" onsubmit="validate();" />
<input type="hidden" name="subtype" id="subtype" value="">
<table border="1">
<tr><td>First Name:</td>
<td><input type="text" name="fname"></td></tr>
<tr><td>last Name:</td>
<td><input type="text" name="lname"></td></tr>
<tr><td>Email:</td><td><input type="text" name="email"></td>
<tr><td>Username:</td><td><input type="text" name="user"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"></td>
<tr><td colspan="2"> <input type="submit" name="Submit" value="Register"></td></tr>
</table>`</form>
<div id="RegDiv"></div>
</html>
<强> reg.asp 强>
<%
fname = Request.Form("fname")
lname = Request.Form("lname")
Email = Request.Form("email")
Username = Request.Form("user")
Password = Request.Form("pass")
getSub = Request.Form("subtype")
if StrComp(getSub,"Register", 1)+1 then
Dim goby
goby=0
if len(Email)<= 5 then
goby=1
end if
if Instr(1, Email, "@", 1) <2 then
goby=1
else
if Instr(1, Email, ".", 1) <4 then
goby=1
end if
end if
if fname ="" OR fname = vbNullString then
response.write("Please provide your first name")
ElseIf lname="" OR lname=vbNullString then
response.write("Please provide your last name")
ElseIf Email="" OR Email=vbNullString then
response.write("Please provide your email")
ElseIf goby<>0 then
response.write("<span style='#F00'>Please provide a real email address!</span>")
ElseIf Username="" OR Username=vbNullString then
response.write("Please provide your Username")
ElseIf Password="" OR Password=vbNullString then
response.write("Please provide your Password")
else
response.write("Your form was processed successfully")
end if
end if
%>
我认为破坏原始代码的主要原因是JavaScript返回功能。因为你在pass.asp周围没有引号,所以函数可能会将其作为你需要生成的返回值,并在事件发生之前将你传递给那个页面。