 |
| Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 1st, 2006, 07:36 PM
|
|
Authorized User
|
|
Join Date: Nov 2005
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Looking for an elegant solution
I have a working webpage, but I am thinking there's a more elegant solution than this "brute force" method.
I have a drop down <select> box that lists each month, and want it to have the current month selected automatically. I dim a variable and initialize it:
curMonth = MonthName(Month(Date))
Then I have 12 of the following, one for each month:
If curMonth="January" Then
Response.Write "<OPTION VALUE='January' SELECTED='Selected'>January</OPTION>"
Else
Response.Write "<OPTION VALUE='January'>January</OPTION>"
End If
Is there a more elegant solution than having one of these code chunks for each month?
|
|

February 2nd, 2006, 05:15 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
|
|
You could do something like this...
Code:
Dim curMonth
curMonth = Month(Date)
Dim monthArr
monthArr = Array("January", "February", "March", "April", "May", "June", _
"July", "August", "September", "October", "November", "December")
Dim i
For i = 0 To UBound(monthArr)
Dim selected
If i + 1 = curMonth Then
selected = " selected=""selected"""
Else
selected = ""
End If
Response.Write "<option value=""" & monthArr(i) & """" & selected & ">" & monthArr(i) & "</option>"
Next
|
|

February 2nd, 2006, 07:13 PM
|
|
Authorized User
|
|
Join Date: Nov 2005
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Great, thanks for the direction... I got it to work with some modifications.
Dim curMonth
curMonth = MonthName(Month(Date))
Dim monthArr
Dim selected
monthArr = Array("January", "February", "March", "April", "May", "June", _
"July", "August", "September", "October", "November", "December")
Dim i
For i = 0 To UBound(monthArr)
If monthArr(i) = curMonth Then
selected = "selected='selected'"
Else
selected = ""
End If
Response.Write "<option value='" & monthArr(i) & "' " & selected & ">" & monthArr(i) & "</option>"
Next
|
|

February 2nd, 2006, 07:54 PM
|
|
Registered User
|
|
Join Date: Jan 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
how abt this ?
for i = 0 to 11
selected = ""
if (currMonth = i-1) selected = " selected "
response.write "<option value='" & MonthName(i) & "'" & selected & ">" & MonthName(i) & "</option>"
next i
thanks
jigs
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| need solution |
nandhamca22 |
CSS Cascading Style Sheets |
1 |
February 7th, 2006 10:16 AM |
| solution |
hbou |
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 |
0 |
February 9th, 2005 07:30 AM |
| what's the best solution for: |
eresina |
ASP.NET 1.0 and 1.1 Basics |
2 |
November 16th, 2004 10:46 AM |
| Which solution should go |
eureka |
BOOK: ASP.NET Website Programming Problem-Design-Solution |
1 |
September 5th, 2004 12:09 AM |
| Elegant solution preserving info |
Birger |
Excel VBA |
1 |
June 10th, 2003 03:18 AM |
|
 |