Solved

How to add functionality to this select box?

Posted on 2002-03-12
17
161 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
Comment Utility

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
Comment Utility
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
Comment Utility

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
Comment Utility


***************************
<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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 1

Expert Comment

by:dawesi
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
The loop should go from -3 to 8 instead of -3 to 9

Jimmy
0
 
LVL 1

Expert Comment

by:dawesi
Comment Utility
it's getting late here in Sydney...
0
 
LVL 5

Expert Comment

by:Yog
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
this works great!
thanks
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

12 Experts available now in Live!

Get 1:1 Help Now