View Full Version : asp var loop

11-13-2003, 11:51 AM
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

<%For i=1 to number%>

<input type="text" name="name<%=i%>" value="">


This produces

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

name1 = request.form(name1)
name2 = request.form(name2)

then using a var strBody to build up the e-mail content.

So far I have

For i = 1 to number

strBody = strBody & "name" & i & "= " & name & i


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

& 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

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


the value of the var is displayed

any help would be greatly appreciated.

11-13-2003, 12:16 PM
Shouldn't this

For i = 1 to number

strBody = strBody & "name" & i & "= " & name & i



For i = 1 to number
strBody = strBody & "Name " & i & " = " & request.form("name" & i )

11-13-2003, 12:41 PM
Thank You for your help it works oerfectly now.

11-13-2003, 12:45 PM
No problem. Glad you got it running :thumbsup:

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum