简体   繁体   中英

I want the result goes to main page

I'm having a difficult time in getting to work this out, Im new to classic asp and javascript. Hope someone will help me clear this out. I want to view the response.write on the main.asp (or the result) but everytime i try this, it goes to pass.asp (on another page) :(

here's my code. 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>

and here's my 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
%>

your code is... strange at best. you have a return on a function with no return value that should do nothing and you use your submit button for detecting if a user is registering. try changing your code to this and see if if helps at all.

Changes:

removed return action from form onSubmit

added hidden value to check if registering

had javascript set form value for submit type

Edit: added an inclued sataement to merge main and reg.asp into one page

Edit: changed action of form to main.asp

Edit: fixed some typos

Edit: changed = to StrComp function

Edit: forgot to add id to hidden value

Edit: removed StrComp for empty strings as it caused errors

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
%>

The main thing I think broke your original code was that JavaScript return function. because you did not have quotes around pass.asp the function likely took that as the return value you needed to generate and was passing you to that page before the post action actually happened.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM