Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Help with For/Next statement
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Help with For/Next statement

 Post Reply Post Reply
Author
betheball View Drop Down
Newbie
Newbie


Joined: 28 April 2002
Location: United States
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote betheball Quote  Post ReplyReply Direct Link To This Post Topic: Help with For/Next statement
    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.

Back to Top
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
betheball View Drop Down
Newbie
Newbie


Joined: 28 April 2002
Location: United States
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote betheball Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
vshriniwasan View Drop Down
Groupie
Groupie
Avatar

Joined: 17 December 2001
Location: United States
Status: Offline
Points: 63
Post Options Post Options   Thanks (0) Thanks(0)   Quote vshriniwasan Quote  Post ReplyReply Direct Link To This Post 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)
%>

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
vshriniwasan View Drop Down
Groupie
Groupie
Avatar

Joined: 17 December 2001
Location: United States
Status: Offline
Points: 63
Post Options Post Options   Thanks (0) Thanks(0)   Quote vshriniwasan Quote  Post ReplyReply Direct Link To This Post 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...
Back to Top
betheball View Drop Down
Newbie
Newbie


Joined: 28 April 2002
Location: United States
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote betheball Quote  Post ReplyReply Direct Link To This Post 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>

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.