TobbeK 0 Junior Poster

I have a small problem with this select box.

This one loops out [year-month] in 12 month periods starting from the current month. When a selection has been done, a month value is sended back to this select box so that the selected month then stays selected. That works, as long as the current month is NOT bigger than the ending month. If it's equal or bigger then it works.

Example:
--------------
2008-03 (Equal month as the ending month)
2008-04
2008-05
2008-06
2008-07
2008-08
2008-09
2008-10
2008-11
2008-12
2009-01 (Problem)
2009-02 (Problem)
2009-03 (Equal month as the starting month)

A value from the example cannot be used if the month value is smaller than the current month (2008-03).

<select name="ymvalue" class="usermenuform" size="1" onchange="ymform.submit()">
<option value="0">- year / month -</option>

<%

Session("ym") = Request.Form("ymvalue")

YM = Session("ym")
a = date()


If YM <> "" Then
 	If YM > "0" Then

x = 1
For i = DatePart("m",a) To DatePart("m",Session("ym"))
x = x +1
Response.Write("<option value=" & Year(a)&"-"&Right("0" & Month(a),2) & " SELECTED >" & Year(a)&"-"&Right("0" & Month(a),2) & "-</option>")
a = DateAdd( "m", 1, a )
Next

x = x -1

For i = 0 To 12 -x
Response.Write("<option value=" & Year(a)&"-"&Right("0" & Month(a),2) & ">" & Year(a)&"-"&Right("0" & Month(a),2)  & "-</option>")
a = DateAdd( "m", 1, a )
Next

	End If
End If


If YM = "" OR YM = "0" Then

For i = 0 To 12
Response.Write("<option value=" & Year(a)&"-"&Right("0" & Month(a),2) & ">" & Year(a)&"-"&Right("0" & Month(a),2)  & "-</option>")
a = DateAdd( "m", 1, a )
Next
End If

%>

</select>