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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass variables via POST

Status
Not open for further replies.

bipink

Programmer
Apr 15, 2004
14
US
Hi everyone,

Is it possible to pass only variables bt. ASP pages.
I have 3 asp pages.
In page1.asp, I have a text box text1.
When I submit this page, in page2.asp I use the contents of page1's text1 as var2= Request.form("text1") and on doing some db query, I get some value for text box text2 on page2.asp.
Now when I press the submit on page2, I want to have both values of text boxes of page1.asp and page2.asp. But now the problem is my page3.asp receives only the value of text2 and NOT text1 (var2).
So, I get var32 = Request.form("text2").

But this doesn't work -> var31=Request.form("var2");

How do I then get var2 from page2.asp on page3.asp. In other words how to get value of text1 from page1.asp on page3.asp ?

One way is to make a hidden textbox on page2 and store the value of text1 in it and retrieve it on page3. Is there a better way ?

Thanks,

Bipin
 
pretty quick fix it seems

you can use a loop to go through the form values :

for each element in request.form
response.write element & ": " & request(element)
' convert this line around / add some conditionals as needed
next

perhaps use naming conventions per page like page1text1 and page2text1 then use the for/next with a conditional to filter for only the prior pages values
you can also use the fornext loop to build the input boxes and completely keep passing values along.
 
Dear DreXor,

Can you please explain/elaborate ?
I didn't understand properly.

Thanks,

bipin
 
getting back to making sample code, sorry for the delay, the help here descided to lose a 50$ pair of cat5 crimps, still have yet to locate them.
 
No proble DreXor, take your time.
thanks,

bipin
 
ok code up, i have a running sample online @
source code here in case of connectivity or removal of the temp files.

Page1.asp
Code:
<html>
<body>
<%
' putting in some arrays and loops to generate the page code a little faster
' and populating it with some easy values
pagenum=1
numTextElements = 5
%>
<form method="post" action="page<%=pagenum+1%>.asp">
<%
' making the form elements 
for i=1 to numTextElements
%>
<%="Page" & Pagenum & "text" & i%>: <input type="text" name="<%="Page" & Pagenum & "text" & i%>" value="<%=i * 5%>"><br>
<%
Next
%>
<input type="submit"><br>
this little "loop" can continue as long as necessary for subsequent forms
</form>
</body>
</html>

Page2+.asp ( modify pagenum and save filename appropriate to match )
Code:
<html>
<body>
<%
' putting in some arrays and loops to generate the page code a little faster
' and populating it with some easy values
pagenum=3
numTextElements = 5
%>
<form method="post" action="page<%=pagenum+1%>.asp">
<%
' grabbing and adding on the old values 
for each element in request.form
'these elements can be hidden dont disable them otherwise they will not pass.
%>
<%=element%> : <input type="text" value="<%=request(element)%>" name="<%=element%>"><br>
<%
next
' little divider for the seperate section
%>
<hr>
<%
' making the form elements 
for i=1 to numTextElements
%>
<%="Page" & Pagenum & "text" & i%>: <input type="text" name="<%="Page" & Pagenum & "text" & i%>" value="<%=i * 5%>"><br>
<%
Next
%>
<input type="submit">
</form>
</body>
</html>
 
<clip src="thread333-827695">
the prior form values can be hidden or visible, if they are made disabled they wont carry across. also if you use a naming convention for the field names and locations, you can then use this to filter which ones you want hidden or visible.

if you do not understand the asp code i would be more than happy to help explaining it in more detail
</clip>
 
also in the online sample of the operational code, i updated page3, so it will report to itself and autoincrement, so you will stack up hoards of form elements, and feel free to change the values
 
also please note, just because it's pre-populated with numbers ( that was just for ease of ensuring right values are being passed ) these values can be changed and will stay changed
 
Dear DreXor,

Thanks for your reply.
But actually I think u got my problem wrong.
Maybe I wasn't clear.
What I am eager to know is what is the best way to access (know) the values of text boxes on page1.asp when I am in page3.asp.
My route is page1.asp -> page2.asp -> page3.asp

Is this the only way to do that:
I create hidden text boxes in page2.asp and store the value of page1.asp text boxes (I get the values by using request.form) and then in page3.asp, I retrieve the values of the hidden boxes in page2 so that I get values of boxes in page1.asp.

If this is what you replied to, then I'm sorry I still didn't understand. :-(
Please tell me if you get what I am asking, otherwise will state again.
Thanks so much,

Sincerely,
bipin
 
and yes sorry for the confusion, it is what i had replied to.

just because they aren't hidden in the sample pages doesn't mean they cant be, and you can directly request them in page3

if you haven't taken the opportunity to look at the sample pages i put up they're available at fill in the forms and look at the values on the next page, each page is only generating 5 new fields all the others are being carried.

because of the extreme dynamic nature of your pages, unknown record count and unknown number of fields, and on top of that, they are all modifyable, then you need to work with some loops and dynamics

which is the sample i showed you .. if you'd like only the prior page to be visible and the prior pages to be invisible, that's just a matter of a conditional to be added, if that's what you'd like i'd be happy to add that in.
 
Hi Drexor,

Thanks for the reply once again.
But the link is not working.
On reading your reply, I infer that my idea of keeping hidden boxes is the only way to go. You too I guess have suggested the same but ur way of creating the hidden boxes is dynamic (I think).
There is no other way than creating hidden boxes to pass info. of page1.asp to page3.asp. Right ?
I would like to know that (a yes or no would do - i don't want to trouble you).
Thanks,

Sincerely,
Bipin
 
the creation on each page ( the new ones ) is dynamic yes, but as for the prior page ones, you can use HTML pages with static forms and it'll still pass the values along with the script i gave you, the portion of it is in :

<form method="post" action="whateverpage.asp">
<%
' grabbing and adding on the old values
for each element in request.form
%>
<%=element%> : <input type="hidden" value="<%=Server.HTMLEncode(request(element))%>" name="<%=element%>">
<%
next
%>
</form>

that will replicate all form values issued to the page. if you want to cover any form of input passed ( including querystring ) use this :

<form method="post" action="whateverpage.asp">
<%
' grabbing and adding on the old values
for each element in request.form
%>
<%=element%> : <input type="hidden" value="<%=Server.HTMLEncode(request(element))%>" name="<%=element%>">
<%
next
for each element in request.QueryString%>
<%=element%> : <input type="hidden" value="<%=Server.HTMLEncode(request(element))%>" name="<%=element%>">
<%
next
%>
</form>


hope that helps, and sorry the pages weren't working, due to the number of "nice" people on the internet, i lock down my server for the evening hours since it is a personal server. if you attempt the page during somewhat daytime hours ( USA ) then it should work for you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top