• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1756
  • Last Modified:

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"))
0
countrymeister
Asked:
countrymeister
1 Solution
 
rlbalanCommented:
Looks like you need the data in a new window. So you will have to pass the parameters to the new window to access it or shud use JS to get the value from the opener page.

Option 1 : Request parameters:
In the case.. the Callredirect will change to something like
function CallRedirect(){
  var elems = document.forms[0].elements;
  window.open("preview_form.asp?select_prefix=" + elems["select_prefix"] + "&FirstName=" + elems['FirstName"] +"&MiddleName=" + elems[""])    
}

Then your code in preview_form.asp does not need any change and you can get the values in the request.

Option2: using pure JS to get values
In this case Callredirect() is unchanged.. so its just
function CallRedirect(){
  window.open("preview_form.asp")
}

But page2 ("preview_form.asp") will need to be modified as follows

Page2.asp

<script>
function doOnLoad() {
  var opener = document.opener;
  var elems;
  if(opener && opener.forms[0] )
   elems = opener.forms[0].elements;

  if(!elems) {alert('no elements'); return;}

  var firstName = elems["FirstName"];
  var middleName = elems["MiddleName"];

You can then use these values and populate the contents in the form of page2


HTH

}
</script>
<body onLoad="doOnLoad()" ..> ...

</body>
0
 
deathtospamCommented:
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 =-
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now