Solved

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

Posted on 2002-03-07
5
267 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 50 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Remove Index.php in Codeigniter 12 64
Unsearchable in Google,Yahoo and Bing. 6 62
Web server settings related to keepalive 1 122
Website URL redirection 10 69
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

825 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