Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: asp var loop

  1. #1
    New Coder
    Join Date
    Feb 2003
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    asp var loop

    I have an .asp page that pulls in a number a form is then displayed with 3 text boxes if the number entered is 3 or 16 text boxes if the number entered is 16 and so on.

    To do this I have used

    Code:
    <%For i=1 to number%>
    
    <input type="text" name="name<%=i%>" value=""> 
    
    <%next%>
    This produces
    Code:
    <input type="text" name="name1" value = "">
    <input type="text" name="name2" value = "">
    and so on

    This works fine and I have even been able to validate the boxes usinh JavaScript with the same technique.

    What I now want to do is e-mail the results of what has been entered. This means pulling in the results setting a var to the same name as the txt box name as in:

    Code:
    name1 = request.form(name1)
    name2 = request.form(name2)
    then using a var strBody to build up the e-mail content.

    So far I have

    Code:
    For i = 1 to number
    
    strBody = strBody & "name" & i & "=            " & name & i 
    
    next
    I think you can see where I am going.

    The e-mail then sends and the specified section does not appear.
    I am sure I must be doing something wrong round the
    Code:
    & i &
    section but do not know how else to do this if I try a response.write on these vars using the same technique

    as in
    Code:
    Response.Write(name & i)
    I get 1 2 written on the screen as in the value of i and not the var



    if I try

    Code:
    Response.Write(name1)
    the value of the var is displayed

    any help would be greatly appreciated.

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Shouldn't this
    Code:
    For i = 1 to number
    
    strBody = strBody & "name" & i & "=            " & name & i 
    
    next
    be
    Code:
    For i = 1 to number
       strBody = strBody & "Name " & i & " = " & request.form("name" & i ) 
    next

  • #3
    New Coder
    Join Date
    Feb 2003
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile thank you

    Thank You for your help it works oerfectly now.

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No problem. Glad you got it running


  •  

    Posting Permissions

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