Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamically setting for (loop) variable

Status
Not open for further replies.

wbodger

Programmer
Apr 23, 2007
769
0
0
US
OK, I have this code snippet

Code:
		<tr>
			<td colspan="2"><hr>
				<div align="left">Number of Adult Leaders: <input type="text" name="numleaders" /></div>
			</td>
		</tr>
		<% Dim c : c = 1 %>
		<% FOR c = 1 TO 10 %>
		<tr>
			<td colspan="2"><HR>
				<div align="left"><strong><%=c%>) Name: <input name="name<%=c%>" type="text" id="name<%=c%>" size="40">
					</strong>
				</div>
			</td>
		</tr>
		<tr>
			<td colspan="2"><div align="left"><strong>E-Mail: <input name="email<%=c%>" type="text" id="email<%=c%>"></strong>
				</div>
			</td>
		</tr>
		<tr>
			<td colspan="2"><div align="left"><strong>Age: <input name="age<%=c%>" type="text" id="age<%=c%>"></strong>
				</div>
			</td>
		</tr>
		<tr>
			<td colspan="2"><div align="left"><strong>Gender: <input name="gender<%=c%>" type="radio" id="gender<%=c%>" value="Male">
						Male <input name="gender<%=c%>" type="radio" id="gender<%=c%>" value="Female"> Female </strong>
				</div>
			</td>
		</tr>
		<tr>
			<td colspan="2"><div align="left"><strong>Van Driver? <input name="vandriver<%=c%>" type="radio" id="vandriver<%=c%>" value="Yes">Yes 
						<input name="vandriver<%=c%>" type="radio" id="vandriver<%=c%>" value="No"> No</strong>
				</div>
			</td>
		</tr>
		<tr>
			<td colspan="2" height="44"><div align="left">
				<input type="checkbox" name="skills<%=c%>" value="construction"> Construction (masonry, carpentry, electrical, plumbing, roofing, etc.)<br />
                <input type="checkbox" name="skills<%=c%>" value="worship"> Worship leading/music<br />
				<input type="checkbox" name="skills<%=c%>" value="vbs"> VBS/Children's Ministry<br />
				<input type="checkbox" name="skills<%=c%>" value="speaking"> Speaking<br />
				<input type="checkbox" name="skills<%=c%>" value="medical"> Medical
			</div>
			</td>
		</tr>
		<tr>
			<td colspan="2">&nbsp;</td>
		</tr>
		<% next %>

What I would like to do is take the value entered into numleaders and make that the upper limit in the for loop. Everything else in the page is in vbscript, I write it all to a SQL Server database. Can I incorporate some javascript here to do what I would like to do? If so, can somebody help me out?

Thanks!
WB
 
I presume this is a data entry screen. It looks like what you want is that a user plans to enter information about 7 people so they enter 7 in the number of adult leaders and then bam! 7 collection units would pop up.

I think this can be done and somebody better than me will tell you how I am sure.

I would urge thought about another path.

When a user sits down they might not know how many they are going to enter, or they might type 5 when they meant 6 or they might call Bob mid way thorugh and determine he really didn't want to to do it and need 4 instead of 5.

I think it would be cooler to start by showing one collection unit on the screen and a link at the end of the unit that says "delete this leader" and a button underneath that says "enter another leader and leader information". You enter one leader's stats, hit "enter another" and pop up another collection unit. Mess it up or change your mind? Delete.

I would think you would do this all client side with javascript (or AJAX). And yes, your original idea/request is a client side javascript thing as well unless you make a round trip to the server and reload the page (or AJAX it).

 
Thanks, but I think that just over complicates the form. There is also more group data that is collected at the top of the form which I don't want to re-submit every time and I don't want to break the page into two separate forms. I appreciate the ideas, I just don't think they fit in well with this project.

So, anybody get any ideas on setting the for loop to a number entered in an earlier form field on the same page?
 
Something in line with this:


TT1623095.asp:

Code:
<%
dim nNumLeaders
nNumLeaders = request.Form("fNumLeaders")
if nNumLeaders = "" then nNumleaders = 0

if request.form("fSubmit") = "OK" and nNumLeaders<>0 then
 response.Write "The form is submitted... process the values"
 response.end
end if
%>

<form method=post action=TT1623095.asp>

Number of Adult Leaders: <input type="text" name="fNumleaders" size="3" onchange="submit();" value="<%= nNumLeaders %>"><br />

<% 
 if nNumLeaders > 0 then
 for i = 1 TO nNumLeaders
  %>Name <%= i %>: <input type="text" name="Name<%= i %>"><br /><%
 next 
else
 response.Write "Plz enter a no of leaders..." 
end if
%>

<input type="submit" value="OK" name="fSubmit"/>
</form>

?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top