...

View Full Version : asp var loop



david_stev
11-13-2003, 12:51 PM
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="">

<%next%>


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

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


& 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



Response.Write(name1)


the value of the var is displayed

any help would be greatly appreciated.

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


For i = 1 to number

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

next


be


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

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

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum