Solved

How to add functionality to this select box?

Posted on 2002-03-12
17
164 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

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…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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