how to retrieve elements on next form

W

wk6pack

Hi,

I have a form with the following elements:
first form
<input type='text' name='addr1' value='1223 westward'>
<input type='text' name='addr2' value='12 admirals rd'>
<input type='text' name='addr3' value='90 Northward'>
<input type='text' name='addr4' value='apt 12 34 Marine way'>
<input type='text' name='addr5' value='2nd floor 900 Main St'>

on submit the form will post them to the next form.

second form
<%
while i < 5
response.write("address " & i & " = " & request.form("addr" + i) &
chr(13))
i = i + 1
wend
%>

Is the syntax correct to get the values? I tried it but I dont get any
values for the request.
If it is not the correct syntax, what should it be so I will be able to see
it when the first form posts it to the second one?

thanks,
Will
 
R

Randy Rahbar

while i < 5

With this statement, your 5th address will never be written. Change it to...

while i < 6
response.write("address " & i & " = " & request.form("addr" + i) &
chr(13))

Change the above line to...
response.write("address " & i & " = " & request.form("addr" & i) & chr(13))

(notice the "&" replacing the "+")

Randy
 
T

Tom B

My understanding is that

"addr" & i

would have a space in the string, as i would have a positive or negative
indicator. That is, if i was 1 then it's value as a string would be " 1"
because of the missing + sign.

If you just want to pass your form data along. Try something like....

Dim field
for each field in Request.Form
Response.Write "<input type=hidden name=""" & field & """ value=""" &
Request.Form(field) & """>"
next
 
R

Roland Hall

:
: I have a form with the following elements:
: first form
: <input type='text' name='addr1' value='1223 westward'>
: <input type='text' name='addr2' value='12 admirals rd'>
: <input type='text' name='addr3' value='90 Northward'>
: <input type='text' name='addr4' value='apt 12 34 Marine way'>
: <input type='text' name='addr5' value='2nd floor 900 Main St'>
:
: on submit the form will post them to the next form.
:
: second form
: <%
: while i < 5
: response.write("address " & i & " = " & request.form("addr" + i) &
: chr(13))
: i = i + 1
: wend
: %>
:
: Is the syntax correct to get the values? I tried it but I dont get any
: values for the request.
: If it is not the correct syntax, what should it be so I will be able to
see
: it when the first form posts it to the second one?

Will, I assume when you say 'second form' you mean page. When you're
working with forms you should show all relevant code since <form ...> is
usually the area of interest.

This is a workable solution.

[first.asp]
----------
<%@ Language=VBScript %>
<%
Option Explicit
Response.Buffer = True
%>
<html>
<head>
<script type="text/javascript">
function validate() {
var a = new Array(4);
for(i=0; i<5; i++) {
a = document.getElementById("addr"+(i+1))
if(!a.value) {
alert(a.id + " cannot be blank");
a.focus();
return false;
}
}
document.form1.action="/lab/next.asp";
document.form1.submit();
return true;
}
</script>
<body>
<form id="form1" name="form1" method="post" onSubmit="return validate()">
<input id="addr1" type='text' name='addr1' value='1223 westward' /><br />
<input id="addr2" type='text' name='addr2' value='12 admirals rd' /><br />
<input id="addr3" type='text' name='addr3' value='90 Northward' /><br />
<input id="addr4" type='text' name='addr4' value='apt 1234 Marine way' /><br
/>
<input id="addr5" type='text' name='addr5' value='2nd floor 900 Main St'
/><br />
<input id="submit1" type="submit" name="submit1" value="submit" />
<input id="reset1" type="reset" name="reset1" value="reset" /><br />
</form>
</body>
</html>

[next.asp]
----------
<%@ Language=VBScript %>
<%
Option Explicit
Response.Buffer = True
dim info(5)
dim i
for i = 1 to 5
info(i)=Request.Form("addr" & i)
Response.Write("Address " & i & " = " & info(i) & "<br />" & vbCrLf)
next
%>

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
W

wk6pack

Thanks Peter, that works great now.
Will

Peter Foti said:
Oops, I forgot 2 things....
1. Set i to 1 before the loop
2. Do while i < 6 instead of 5.

Thus, first 3 lines should be:
<%
i = 1
while i < 6

The rest remains the same.
Regards,
Peter
 
W

wk6pack

Got it. thanks for you reply.
Will
Roland Hall said:
:
: I have a form with the following elements:
: first form
: <input type='text' name='addr1' value='1223 westward'>
: <input type='text' name='addr2' value='12 admirals rd'>
: <input type='text' name='addr3' value='90 Northward'>
: <input type='text' name='addr4' value='apt 12 34 Marine way'>
: <input type='text' name='addr5' value='2nd floor 900 Main St'>
:
: on submit the form will post them to the next form.
:
: second form
: <%
: while i < 5
: response.write("address " & i & " = " & request.form("addr" + i) &
: chr(13))
: i = i + 1
: wend
: %>
:
: Is the syntax correct to get the values? I tried it but I dont get any
: values for the request.
: If it is not the correct syntax, what should it be so I will be able to
see
: it when the first form posts it to the second one?

Will, I assume when you say 'second form' you mean page. When you're
working with forms you should show all relevant code since <form ...> is
usually the area of interest.

This is a workable solution.

[first.asp]
----------
<%@ Language=VBScript %>
<%
Option Explicit
Response.Buffer = True
%>
<html>
<head>
<script type="text/javascript">
function validate() {
var a = new Array(4);
for(i=0; i<5; i++) {
a = document.getElementById("addr"+(i+1))
if(!a.value) {
alert(a.id + " cannot be blank");
a.focus();
return false;
}
}
document.form1.action="/lab/next.asp";
document.form1.submit();
return true;
}
</script>
<body>
<form id="form1" name="form1" method="post" onSubmit="return validate()">
<input id="addr1" type='text' name='addr1' value='1223 westward' /><br />
<input id="addr2" type='text' name='addr2' value='12 admirals rd' /><br />
<input id="addr3" type='text' name='addr3' value='90 Northward' /><br />
<input id="addr4" type='text' name='addr4' value='apt 1234 Marine way' /><br
/>
<input id="addr5" type='text' name='addr5' value='2nd floor 900 Main St'
/><br />
<input id="submit1" type="submit" name="submit1" value="submit" />
<input id="reset1" type="reset" name="reset1" value="reset" /><br />
</form>
</body>
</html>

[next.asp]
----------
<%@ Language=VBScript %>
<%
Option Explicit
Response.Buffer = True
dim info(5)
dim i
for i = 1 to 5
info(i)=Request.Form("addr" & i)
Response.Write("Address " & i & " = " & info(i) & "<br />" & vbCrLf)
next
%>

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top