Link to home
Create AccountLog in
Avatar of countrymeister
countrymeister

asked on

How to pass values from one asp page to another on a button click

I have a Classic asp page (page1) with about twenty fields, I have two buttons, Submit and Preview.
On submit the form is validated for the fields filled in and submitted to the database.

On clicking the Preview button, I woud like to redirect the user to another page where the user can display the twenty fields that he filled in.

How do I redirect an user to another page and access the data that was entered in Page1
I tried the following , but i does not work
Page 1
<input type="button" name="preview_form" value="Preview" class="regbutton1" OnClick= "CallRedirect()">

and then I have a Jscript function
function CallRedirect(){
  window.open("preview_form.asp")
}

Page 2
Prefix=trim(Request.Form("select_prefix"))
FirstName=trim(Request.Form("FirstName"))
MiddleName=trim(Request.Form("MiddleName"))
LastName=trim(Request.Form("LastName"))
BadgeTitle=trim(Request.Form("BadgeTitle"))
Suffix=trim(Request.Form("Suffix"))
Email=trim(Request.Form("Email"))
Phone=trim(Request.Form("Phone"))
EveningPhone=trim(Request.Form("EveningPhone"))
AlternativePhone=trim(Request.Form("AlternativePhone"))
ASKER CERTIFIED SOLUTION
Avatar of rlbalan
rlbalan

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Member_2_3718378
Member_2_3718378

Here's a demonstration of how to do what you want, while providing the option of doing both client-side (Javascript) validation on the first page, and server-side (ASP/VBScript) processing on the second page.  

Create a new page, called PageOne.asp, and paste this code into it:

==============================================================
<html lang="en-US">
      <head>
            <title>Experts Exchange Question #22877227</title>
      </head>
      <body>
            <script language="javascript" type="text/javascript">
            <!--
            function Verify(f)
            {
                  if (!f.FirstName.value.length) {
                        alert("Please enter your first name.");
                        f.FirstName.focus();
                        return false;
                  }
                  else if (!f.LastName.value.length) {
                        alert("Please enter your last name.");
                        f.LastName.focus();
                        return false;
                  }
                  else if (!f.Email.value.length) {
                        alert("Please enter your email address.");
                        f.Email.focus();
                        return false;
                  }

                  return true;            
            }
            //-->
            </script>

            <form name="frmPageOne" action="PageTwo.asp" method="POST" onsubmit="return Verify(this)">

            select_prefix = <input type="text" name="select_prefix" value=""><br>
            FirstName (required) = <input type="text" name="FirstName" value=""><br>
            MiddleName = <input type="text" name="MiddleName" value=""><br>
            LastName (required) = <input type="text" name="LastName" value=""><br>
            BadgeTitle = <input type="text" name="BadgeTitle" value=""><br>
            Suffix = <input type="text" name="Suffix" value=""><br>
            Email (required) = <input type="text" name="Email" value=""><br>
            Phone = <input type="text" name="Phone" value=""><br>
            EveningPhone = <input type="text" name="EveningPhone" value=""><br>
            AlternativePhone = <input type="text" name="AlternativePhone" value=""><br>

            <input type="submit" value="Submit To Page 2">

            </form>
      </body>
</html>
==============================================================


Create another page, called PageTwo.asp, and paste this code into it:

==============================================================
<%
Prefix=trim(Request.Form("select_prefix"))
FirstName=trim(Request.Form("FirstName"))
MiddleName=trim(Request.Form("MiddleName"))
LastName=trim(Request.Form("LastName"))
BadgeTitle=trim(Request.Form("BadgeTitle"))
Suffix=trim(Request.Form("Suffix"))
Email=trim(Request.Form("Email"))
Phone=trim(Request.Form("Phone"))
EveningPhone=trim(Request.Form("EveningPhone"))
AlternativePhone=trim(Request.Form("AlternativePhone"))

Response.Write "select_prefix = " & Prefix & "<br>"
Response.Write "FirstName = " & FirstName & "<br>"
Response.Write "MiddleName = " & MiddleName & "<br>"
Response.Write "LastName = " & LastName & "<br>"
Response.Write "BadgeTitle = " & BadgeTitle & "<br>"
Response.Write "Suffix = " & Suffix & "<br>"
Response.Write "Email = " & Email & "<br>"
Response.Write "Phone = " & Phone & "<br>"
Response.Write "EveningPhone = " & EveningPhone & "<br>"
Response.Write "AlternativePhone = " & AlternativePhone & "<br>"
%>
==============================================================


-= DeathToSpam =-