?
Solved

Current month in a select drop-down to be listed first?

Posted on 2002-03-07
5
Medium Priority
?
322 Views
Last Modified: 2013-12-24
I have a simple select drop-down list, all the "month" options are hard coded.  How can I have the drop-down of months auto populated with the current month listed first, and the next month be the listed next in the drop-down?

This is my current select drop-down:

<SELECT NAME= "CurntDate">
<OPTION VALUE= "01/01/2002">January 2002
<OPTION VALUE= "02/01/2002">February 2002
<OPTION VALUE= "03/01/2002">March 2002
<OPTION VALUE= "04/01/2002">April 2002
<OPTION VALUE= "05/01/2002">May 2002
<OPTION VALUE= "06/01/2002">June 2002
</SELECT>
0
Comment
Question by:cgttsp01
  • 3
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
sshhz earned 200 total points
ID: 6849082
cgttsp01,

You can try in a cfloop, i set it to loop 12 times. You may try to limit to how many times it loop, can get the current month value and minus with total months in a year, and if that is end of the year, what action and data that you're planning to display, and so forth. These must take into considerations. Below is just some simple code to generate current's month onwards till adding 12 more mths in the following.

<cfoutput>
<cfset currentdt = now()>
<SELECT NAME= "CurntDate">
<cfloop index="idx" from="1" to="12">    
 <OPTION VALUE="#DateFormat(currentdt, 'dd/mm/yyy')#">#DateFormat(currentdt, 'mmmm yyyy')#</option>
 <cfset currentdt = DateAdd("m", 1, currentdt)>
</cfloop>
</SELECT>
</cfoutput>

Good Luck.

-sshhz-

0
 
LVL 2

Expert Comment

by:sshhz
ID: 6849086

ops, let me correct this sentence, could interpreted wrongly.

"Below is just some simple code to generate current's month onwards till adding 12 more mths in the following"

What i mean is, after getting current's month value, i add 1 month each of this value, as long as the loop is allow, 12 times. Sorry for my poor english.

-sshhz-
0
 

Author Comment

by:cgttsp01
ID: 6849250
Thank you SSHHZ.
Your code works perfect, and your english is OK.
0
 
LVL 2

Expert Comment

by:sshhz
ID: 6849548
Thank you for the grade and points.

Cheers! :)
0
 

Author Comment

by:cgttsp01
ID: 6850597
sshhz,

Just one more thing on your code.
I noticed when I select a month in its drop-down, that when it actions to the month that is selected, it only shows the selected month an ownward.

I need it to show the current month onward.

For example, if I choose "April 2002" in the drop-down, your code produces that month as the current month in the action page, and does not list the current month anymore.

Can you correct this problem?
Thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question