how to retrieve elements on next form

Discussion in 'ASP General' started by wk6pack, Jan 27, 2004.

  1. wk6pack

    wk6pack Guest

    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
    wk6pack, Jan 27, 2004
    #1
    1. Advertising

  2. wk6pack

    Randy Rahbar Guest

    > 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



    "wk6pack" <> wrote in message
    news:...
    > 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
    > <%


    > 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
    >
    >
    Randy Rahbar, Jan 27, 2004
    #2
    1. Advertising

  3. wk6pack

    wk6pack Guest

    Hi Randy,

    That didnt work. I get nothing coming back.

    Will
    "Randy Rahbar" <rvrahbar@_JUNKETY_JUNK_hotmail.com> wrote in message
    news:...
    > > 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
    >
    >
    >
    > "wk6pack" <> wrote in message
    > news:...
    > > 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
    > > <%

    >
    > > 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
    > >
    > >

    >
    >
    wk6pack, Jan 27, 2004
    #3
  4. wk6pack

    Tom B Guest

    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


    "Randy Rahbar" <rvrahbar@_JUNKETY_JUNK_hotmail.com> wrote in message
    news:...
    > > 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
    >
    >
    >
    > "wk6pack" <> wrote in message
    > news:...
    > > 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
    > > <%

    >
    > > 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
    > >
    > >

    >
    >
    Tom B, Jan 28, 2004
    #4
  5. wk6pack

    Roland Hall Guest

    "wk6pack" wrote:
    : 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
    Roland Hall, Jan 28, 2004
    #5
  6. wk6pack

    wk6pack Guest

    Thanks Peter, that works great now.
    Will

    "Peter Foti" <> wrote in message
    news:...
    > 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
    >
    >
    > "Peter Foti" <> wrote in message
    > news:...
    > > "wk6pack" <> wrote in message
    > > news:...
    > > > 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?

    > >
    > > This should do what you want:
    > >
    > > <%
    > > i = 1
    > > while i < 5
    > > frmStr = "addr" & i
    > > Response.Write("address " & i & " = " & Request.Form(frmStr) &

    "<br>")
    > > i = i + 1
    > > wend
    > > %>
    > >
    > >
    > > Note that another option might be to interate through the Form

    collection,
    > > but it will also include the submit button, and any other form inputs
    > > <%:
    > > For Each item in Request.Form
    > > Response.Write(item & " = " & Request.Form(item) & "<br>")
    > > Next
    > > %>
    > >
    > > Regards,
    > > Peter Foti
    > >
    > >

    >
    >
    wk6pack, Jan 28, 2004
    #6
  7. wk6pack

    wk6pack Guest

    Got it. thanks for you reply.
    Will
    "Roland Hall" <nobody@nowhere> wrote in message
    news:%...
    > "wk6pack" wrote:
    > : 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
    >
    >
    wk6pack, Jan 28, 2004
    #7
  8. wk6pack

    wk6pack Guest

    I was missing a couple of things. Thanks for you reply.

    Will
    "Randy Rahbar" <rvrahbar@_JUNKETY_JUNK_hotmail.com> wrote in message
    news:...
    > > 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
    >
    >
    >
    > "wk6pack" <> wrote in message
    > news:...
    > > 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
    > > <%

    >
    > > 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
    > >
    > >

    >
    >
    wk6pack, Jan 28, 2004
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Li Zhang
    Replies:
    4
    Views:
    6,057
    softip
    Feb 27, 2009
  2. Kees de Winter
    Replies:
    3
    Views:
    965
    Karl Seguin [MVP]
    May 12, 2006
  3. Deniz Bahar
    Replies:
    2
    Views:
    463
    Andrey Tarasevich
    Mar 9, 2005
  4. =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki

    Reading of file by next of map file and by next of file descriptor.

    =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki, Jul 10, 2007, in forum: C++
    Replies:
    1
    Views:
    785
    Alf P. Steinbach
    Jul 10, 2007
  5. Tad McClellan
    Replies:
    3
    Views:
    138
    Edward Wijaya
    May 13, 2004
Loading...

Share This Page