Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now