selection problem in a month loop

Thread Solved

Join Date: Feb 2008
Posts: 174
Reputation: TobbeK is an unknown quantity at this point 
Solved Threads: 3
TobbeK TobbeK is offline Offline
Junior Poster

selection problem in a month loop

 
0
  #1
Mar 15th, 2008
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).


  1. <select name="ymvalue" class="usermenuform" size="1" onchange="ymform.submit()">
  2. <option value="0">- year / month -</option>
  3.  
  4. <%
  5.  
  6. Session("ym") = Request.Form("ymvalue")
  7.  
  8. YM = Session("ym")
  9. a = date()
  10.  
  11.  
  12. If YM <> "" Then
  13. If YM > "0" Then
  14.  
  15. x = 1
  16. For i = DatePart("m",a) To DatePart("m",Session("ym"))
  17. x = x +1
  18. Response.Write("<option value=" & Year(a)&"-"&Right("0" & Month(a),2) & " SELECTED >" & Year(a)&"-"&Right("0" & Month(a),2) & "-</option>")
  19. a = DateAdd( "m", 1, a )
  20. Next
  21.  
  22. x = x -1
  23.  
  24. For i = 0 To 12 -x
  25. Response.Write("<option value=" & Year(a)&"-"&Right("0" & Month(a),2) & ">" & Year(a)&"-"&Right("0" & Month(a),2) & "-</option>")
  26. a = DateAdd( "m", 1, a )
  27. Next
  28.  
  29. End If
  30. End If
  31.  
  32.  
  33. If YM = "" OR YM = "0" Then
  34.  
  35. For i = 0 To 12
  36. Response.Write("<option value=" & Year(a)&"-"&Right("0" & Month(a),2) & ">" & Year(a)&"-"&Right("0" & Month(a),2) & "-</option>")
  37. a = DateAdd( "m", 1, a )
  38. Next
  39. End If
  40.  
  41. %>
  42.  
  43. </select>
Last edited by TobbeK; Mar 15th, 2008 at 3:11 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP Forum


Views: 929 | Replies: 0
Thread Tools Search this Thread



Tag cloud for ASP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC