Results 1 to 6 of 6

Thread: request.form using an array??

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537
    I have a form on one page that may have an undetermined amount of elements on it.

    on the next page( the one that will write to the database) I need to use request.form to get the values out of my form from page 1.

    the elements are named like this
    <input name="text1">
    <input name="text2">
    <input name="text3">

    ect......

    how do i use an array on page 2 to get the values from this form?

    this is my crappy attempt at the syntax.

    dim i
    dim text(i)
    i = 1

    for each text in request.form
    text(i) = request.form
    i = i + 1
    next

    I know this is wrong but do you get the idea??

    I could just 'hard code' this thing but that would be a waist of code. plus i never know if the form will have 2 or 3 or 10 text box's.....


    any suggestion???

    thanks
    pnj

  2. #2
    New Member
    Join Date
    Apr 2001
    Location
    Sweden
    Posts
    4
    Give all textfields the same name ..

    <input type="text" name="text"><br>
    <input type="text" name="text"><br>
    <input type="text" name="text"><br>

    .. and on your second page you use the following code to receive the result:

    <%

    Dim lngI
    Dim avntTexts

    avntTexts = Split(Request("Text"), ", ")

    For lngI = 0 To UBound(avntTexts)
    'Do what you want to do with the texts
    Response.Write avntTexts(lngI) & "<br>"
    Next

    %>

    Guess that would do the trick!

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537
    good idea but i'm not sure that would work.

    i need to write the value from the text fields to specific locations in my database.

    so they have to be named text1 ,text2 ect... becouse i need to know where in the database they will go, based on the 1,2,3, value of the name.

    does that make sense?
    pnj

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537
    maybe.......but I just thought of this, send the number of fields to the second page
    using a hidden form field.

    so i will know that i have x number of objects(text box's, radio buttons. ect)

    then i should be able to say something like this:

    x=request.form("hidden")

    dim i
    i=1
    for i = 1 to x
    'some code here....
    next


    i think i can get this to work becouse i will now know how many times to run the loop
    and i can still use the names i need to dump it into the database.???

    I hope...

    your code will probably work but i'm not real sure how to make it work the way i need it to..
    thanks again
    pnj

  5. #5
    Addicted Member Active's Avatar
    Join Date
    Jan 2001
    Location
    Lat: 13° 4' 46" N, Long: 80° 15' 20" E
    Posts
    209
    I assume you have some page(call it page1) like this

    Page1.asp

    Code:
    <form method="post" action="page2.asp">
    <Textarea name="dummytext"></Textarea><br>
    <input type="text" name="dummy" value=""><br>  
    <input type="text" name="text1" value=""><br> 
    <input type="text" name="text2" value=""><br>
    <input type="text" name="text3" Value=""><br>
    <input type="submit" name="sm" Value="Submit">
    </form>
    Then the simplest way to Isolate and get those text1,text2,... values is..

    Page2.asp
    Code:
    <%
    For Each x In Request.Form
     If Lcase(Left(x,4)) = "text" Then
      Response.write ("The value of " & x & " is " & Request.Form(x) & "<BR>")
     'or do whatever you want with x and request.form(x)
     End If
    Next
    %>
    If you can't beat your computer at chess, try kickboxing !!!
    [Download Tag Editing Tools.]

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537
    yea, that looks about what i was going to do.

    it's been a busy weekend...........

    thanks
    pnj

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width