Print Page | Close Window

Help with For/Next statement

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=5243
Printed Date: 30 March 2026 at 3:17pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Help with For/Next statement
Posted By: betheball
Subject: Help with For/Next statement
Date Posted: 24 August 2003 at 9:10am

I am trying to use a For/Next loop to populate a dropdown.  My problem is my code is not inserting a break where needed so all the values show on one line.  Here is the code:

<option>

<%

For i = 1910 to 1990

response.write i & "<br>"

Next

%>

</option>

Can you see my error.




Replies:
Posted By: pmormr
Date Posted: 24 August 2003 at 9:24am

try splitting the i and br writing.

For i = 1910 to 1990

Response.Write i
Response.Write "<br>"

Next



-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: betheball
Date Posted: 24 August 2003 at 12:33pm
No go.  Same result.  I think I need to change the <option> codes because the code is reading all of the possible values for i as one option.


Posted By: vshriniwasan
Date Posted: 24 August 2003 at 12:55pm

This should take care of that...

<%
 Dim i
 Response.Write ("<select name=""name_of_the_dropdown"">" & vbCrlf)
 For i = 1910 to 1990
  Response.Write ("<option value=""" & i & """>" & i & "</option>" & vbCrlf)
 Next
 Response.Write ("</select>" & vbCrlf)
%>



Posted By: Mart
Date Posted: 24 August 2003 at 1:00pm

use VbCrlf it will insert a line break

For i = 1910 to 1990

response.write i & VbCrlf

Next



Posted By: vshriniwasan
Date Posted: 24 August 2003 at 1:40pm
Ya... Otherwise the source looks little ugly. All the <options> are put in the same line. vbCrlf just adds a break...


Posted By: betheball
Date Posted: 24 August 2003 at 4:15pm

Thanks for all the input.  I never realized there were so many ways of doing things.  The following worked for me.  Please let me know if anyone sees any problems that I may not realize.

<select size="1" name="myyear" tabindex="3">

<option selected>Year</option>

<%

For i = 1910 to 1995

%>

<option><% response.write i %></option>

<%

Next

%>

</select>




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net