Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-08-2007, 01:03 PM   PM User | #1
Kal
Regular Coder

 
Join Date: Dec 2005
Posts: 309
Thanks: 0
Thanked 0 Times in 0 Posts
Kal is an unknown quantity at this point
month year drop down

Hi Guys

The following code originally posted by raf works great, howeveri need some help modifying it slightly.

is there away in which it could display all 12 months for the current year? but the default should remain on the current month.

at the moment it only displays the upcoming 5 months. and not the previous months already gone in the year.

thanks in advance

Code:
<select name="month">
							<%
							Dim i2, value, optionv
							i2 = 0
							do while i2 <= 5
							value = Month(DateAdd("m",i2, Now()))
							optionv = MonthName(value) + " " +  Right(Year(Now),2)
							response.write("<option value='" & optionv & "'>"& optionv &"</option>")
							i2= i2+1
							loop
							%>
						</select>
Kal is offline   Reply With Quote
Old 05-08-2007, 02:15 PM   PM User | #2
TheShaner
Senior Coder

 
TheShaner's Avatar
 
Join Date: Sep 2005
Location: Orlando, FL
Posts: 1,125
Thanks: 2
Thanked 40 Times in 40 Posts
TheShaner will become famous soon enoughTheShaner will become famous soon enough
Code:
<select name="month">
<%
  Dim i, cur_month, optionv, sel_text
  sel_text = ""    'Display whether the month is selected
  cur_month= Month(Now) 'Current Month's integer
  For i = 1 To 12
    If (i = cur_month) Then sel_text = " selected='selected'" 
    optionv = MonthName(i) & " " &  Right(Year(Now), 2)
    Response.Write("<option value='" & optionv & "'" & sel_text & ">" & optionv & "</option>")
  Next
%>
</select>
The above code is just looping through all 12 months and displaying them. If during the loop it comes to a month that is equal to the current month's integer, then it'll display the text to make sure that month is selected by default in the drop down.

-Shane
TheShaner is offline   Reply With Quote
Old 05-08-2007, 04:37 PM   PM User | #3
Kal
Regular Coder

 
Join Date: Dec 2005
Posts: 309
Thanks: 0
Thanked 0 Times in 0 Posts
Kal is an unknown quantity at this point
thanks for your reply just tested your code and it seems to default to December 07 rather than May 07.
Kal is offline   Reply With Quote
Old 05-08-2007, 04:52 PM   PM User | #4
TheShaner
Senior Coder

 
TheShaner's Avatar
 
Join Date: Sep 2005
Location: Orlando, FL
Posts: 1,125
Thanks: 2
Thanked 40 Times in 40 Posts
TheShaner will become famous soon enoughTheShaner will become famous soon enough
My fault! What was happening was that once it got to May, although it set the text to display the selected='selected' in the May 07 option, it never reset it back to nothing and so every month after it also received selected='selected'. If you look at the source code, you'll see. I tested the below code and it works. The red text indicates the changed code.
Code:
<select name="month">
<%
  Dim i, cur_month, optionv, sel_text
  sel_text = ""    'Display whether the month is selected
  cur_month= Month(Now) 'Current Month's integer
  For i = 1 To 12
    If (i = cur_month) Then
      sel_text = " selected='selected'" 
    Else
      sel_text = ""
    End If
    optionv = MonthName(i) & " " &  Right(Year(Now), 2)
    Response.Write("<option value='" & optionv & "'" & sel_text & ">" & optionv & "</option>")
  Next
%>
</select>
-Shane
TheShaner is offline   Reply With Quote
Old 05-08-2007, 04:55 PM   PM User | #5
Kal
Regular Coder

 
Join Date: Dec 2005
Posts: 309
Thanks: 0
Thanked 0 Times in 0 Posts
Kal is an unknown quantity at this point
thanks shane works great. i looked at the source code and see what you mean.
Kal is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:26 AM.


Advertisement
Log in to turn off these ads.