Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to pass data between forms 1

Status
Not open for further replies.

hxx

Technical User
Oct 26, 2000
10
MY
which is the easiest method to pass data between forms? is using session object is the best way?....i just want to pass the data entered by user to another form...for instance, when user type in his name, it will be displayed in the next form. it does not involve any database....can u show me how's the code like?
 
If the form where the user enters his data is going directly to another form then the data is best passed using the POST method in the FORM.

The following example is of a web page containing two fields - one for surname, and one for forename:

Code:
<html>
<head>
  <title> My Form </title>
</head>
<body>
<form name=&quot;frmMyForm&quot; action=&quot;myasp.asp&quot; method=&quot;POST&quot;>
  Surname:<input type=&quot;text&quot; name=&quot;txtSurname&quot;><br>
  Forename:<input type=&quot;text&quot; name=&quot;txtForename&quot;><br>
  <input type=&quot;Submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;>
</form>
</html>

This example shows you how to get this data in the asp page that is called by the form:

Code:
<%
   dim strSurname, strForename

   'get the surname entered in the form
   strSurname = Request.Form(&quot;txtSurname&quot;)
   
   'get the forename entered in the form
   strForename = Request.Form(&quot;txtForename&quot;)

   'to store this data in the Session object for use in other pages
   Session(&quot;Surname&quot;) = txtSurname
   Session(&quot;Forename&quot;) = txtForename

%>

As you can see I have added code to put the data into Session variables so that other pages can now get access to this data, otherwise only thi ASP called from the Form in the first web-page would be able to see this data.

Hope this helps.

James :)
James Culshaw
jculshaw@active-data-solutions.co.uk
 
thanx...
I've tried to pass the value(username) using normal parameter...but it just won't work. There was no error shown..just that the result(name entered) is not there. The method that I've used is as followed:

The &quot;name&quot; from form1.asp is passed to form2.asp. In form2.asp, I used <%Response.Write Request.Form(&quot;name&quot;)%> to display the user's name. Is anything wrong with this?...With this, the name just could not be displayed. Why?....Please explain to me....Thanks!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top