PDA

View Full Version : Passing Variables from Page to Page


admin
05-28-2003, 11:10 PM
This uses hidden fields in a POSTED form...

Let's assume you have a form and in that form you have a text field named visitor_name. After the visitor types in their name and clicks on the submit button the next page is viewed. On this new page you do a request.form("visitor_name") to fetch the value that was entered...

visitorname = request.form("visitor_name")

On this new page you have another form and there is another text field, this one named visitor_city...

<FORM Method="Post" Action="theNextPage.asp">
<INPUT Type="Text" Name="visitor_city" Size="20">
<INPUT Type="Hidden" Name="visitor_name" Value="<%=visitorname%>">

Note the hidden field above. The value is whatever the visitor typed in the form from the last page. The visitor can't see this though because it's "Hidden".

Once this form is submitted, the next page just request.form() for both fields...

visitorname = request.form("visitor_name")
visitorcity = request.form("visitor_city")

And then now you can use both values in a sql string...
SQL="Select * From tableVisitors Where VisitorName = '"&visitorname&"' And City = '"&visitorcity&"'"

You don't have to use a value a visitor typed in, you can use pretty much anything. You can use a server variable, the time, a session ID, anything.

And that's the basic concept of passing values from page to page using a hidden form field.