Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 1st, 2006, 07:36 PM
Authorized User
 
Join Date: Nov 2005
Location: , , .
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?
Reply With Quote
  #2 (permalink)  
Old February 2nd, 2006, 05:15 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
Reply With Quote
  #3 (permalink)  
Old February 2nd, 2006, 07:13 PM
Authorized User
 
Join Date: Nov 2005
Location: , , .
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #4 (permalink)  
Old February 2nd, 2006, 07:54 PM
Registered User
 
Join Date: Jan 2006
Location: San Francisco, CA, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:03 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.