Solved

How to add functionality to this select box?

Posted on 2002-03-12
17
162 Views
Last Modified: 2013-12-24
How can I change this select drop-down list to have the previous 3 months from the current month listed in the drop-down, but still default to the current month?

/************************************************/
<SELECT NAME= "CurntDate">

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

/************************************************/
0
Comment
Question by:cgttsp01
  • 4
  • 4
  • 3
  • +4
17 Comments
 
LVL 3

Expert Comment

by:winningl
ID: 6857995

try

***************************
<SELECT NAME= "CurntDate">

<cfloop index="idx" from="1" to="12">    
<OPTION VALUE="#DateFormat(CurntDate, 'mm/dd/yyyy')#"
<cfif #idx# is #month(Now())#>
selected</cfif> >
#DateFormat(CurntDate, 'mmmm yyyy')#</option>
<cfset CurntDate = DateAdd("m", 1, CurntDate)>
</cfloop>
</SELECT>

winningl
0
 
LVL 1

Expert Comment

by:g118481
ID: 6858089
winningl,

I tried your code, however, it does not produce three months prior to the current month, and it selects three months forward of the current month in the field.

Any other ideas?  I really appreciate your help!
0
 
LVL 3

Expert Comment

by:winningl
ID: 6858092

try

***************************
<SELECT NAME= "CurntDate">

<cfloop index="idx" from="1" to="12">    
<OPTION VALUE="#DateFormat(CurntDate, 'mm/dd/yyyy')#"
<cfif #idx# is #month(Now())#>
selected</cfif> >
#DateFormat(CurntDate, 'mmmm yyyy')#</option>
<cfset CurntDate = DateAdd("m", 1, CurntDate)>
</cfloop>
</SELECT>

winningl
0
 
LVL 3

Expert Comment

by:winningl
ID: 6858107


***************************
<cfset startDate = DateAdd("m", -3, Now())>
<SELECT NAME= "CurntDate">

<cfloop index="idx" from=#month(startDate)# to=#month(Now())#>    
<OPTION VALUE="#DateFormat(startDate, 'mm/dd/yyyy')#"
<cfif #idx# is #month(Now())#>
selected</cfif> >
#DateFormat(startdate, 'mmmm yyyy')#</option>
<cfset startdate= DateAdd("m", 1, startdate)>
</cfloop>
</SELECT>

winningl
0
 
LVL 1

Expert Comment

by:g118481
ID: 6858110
winningl,

your most recent code seems to be the same as your previous example.  Am I missing something here?

Thanks again for your time.
0
 
LVL 1

Expert Comment

by:g118481
ID: 6858122
winningl,

I tried your most recent code.
When I run the web page it is in, it is blank.
0
 
LVL 6

Expert Comment

by:reitzen
ID: 6858214
Your select is blank because nothing is being output.  Simply wrap the DateFormat line with a set of <CFOUTPUT> tags.
0
 

Author Comment

by:cgttsp01
ID: 6858727
reitzen,

I really wish you were correct, however, I already had <CFOUTPUT> tags wrapped around it, and it still produces nothing in the drop-down.

Any other suggestions?
0
Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

 
LVL 1

Expert Comment

by:dawesi
ID: 6858833
Try this little gem...

<SELECT NAME="CurrentDate" STYLE="width:100;">
     <CFLOOP INDEX="Count" FROM="0" TO="-2" STEP="-1">
          <OPTION VALUE="#Month(DateAdd("m",Count,Now()))#">#MonthAsString(Month(DateAdd("m",Count,Now())))#</OPTION>
     </CFLOOP>
</SELECT>
0
 

Author Comment

by:cgttsp01
ID: 6860502
dawesi,

I'm suprised you submitted your last code as a "Porposed Answer" , because if you had tested it you would have seen that it does not come close to my requirements.

However, I do appreciate your efforts.

This is a reitteration of my requirements:
1. The select box needs to show the 12 months of the year.
2. The current month needs to show automatically in the box.
3. When the drop-down is selected, in order to view the drop-down contents, the future month needs to be next in line.
4. At least the previous 3 months from the present month needs to preceed the current month in the drop-down list.

If I have not stated these clearly enough, please let me know.
0
 
LVL 1

Expert Comment

by:dawesi
ID: 6860623
All right I was tired...sorry...

1 yep, 2 yep, 3 yep, 4 yep all accounted for

Luv and free code,
Dawesi xxoo

<SELECT NAME="CurrentDate">
     <CFLOOP INDEX="Count" FROM="-3" TO="9" STEP="1">
          <OPTION VALUE="#Month(DateAdd("m",Count,Now()))#" <CFIF DateAdd("m",Count,Now()) EQ DateAdd("m",0,Now())> SELECTED</CFIF>>#MonthAsString(Month(DateAdd("m",Count,Now())))#</OPTION>
     </CFLOOP>
</SELECT>
0
 
LVL 11

Expert Comment

by:jimmy282
ID: 6860652
The loop should go from -3 to 8 instead of -3 to 9

Jimmy
0
 
LVL 1

Expert Comment

by:dawesi
ID: 6860707
it's getting late here in Sydney...
0
 
LVL 5

Expert Comment

by:Yog
ID: 6861101
you can actually add -1 in dateadd to get the previous month same date

#DateFormat(DateAdd("m", -1, "03/13/2002"))#

0
 

Author Comment

by:cgttsp01
ID: 6862178
dawesi,

Your code looks and works great.
However, there is one final thing that needs worked out.

If you look at my original code, you will see that I need the "options" in the select drop-down to format the month as "mm/dd/yyy" (ex. 03/01/2002) and I need the viewable output (what the user sees) to be "mm yyyy" (ex. March 2002).

I know you have worked hard on this question, and I appreciate it.  Also, I have increased the points to "100" compensate you for that time.

Thanks again.
0
 
LVL 1

Accepted Solution

by:
dawesi earned 100 total points
ID: 6863162
Take away the MonthAsString(Month( )) and use
DateFormat( x

<SELECT NAME="CurrentDate">
    <CFLOOP INDEX="Count" FROM="-3" TO="9" STEP="1">
         <OPTION VALUE="#Month(DateAdd("m",Count,Now()))#" <CFIF DateAdd("m",Count,Now()) EQ DateAdd("m",0,Now())>
SELECTED</CFIF>>#DateFormat(DateAdd("m",Count,Now()),'mm yyyy')#</OPTION>
    </CFLOOP>
</SELECT>
0
 

Author Comment

by:cgttsp01
ID: 6882863
this works great!
thanks
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intranet Solution - Sharepoint Foundation or up 4 60
LAMP problem identifier tool ? 9 108
New OSQA server has a ton of fake users 4 54
Domino Website - Redirection 12 47
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
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…
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…

919 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

14 Experts available now in Live!

Get 1:1 Help Now