Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to add functionality to this select box?

Posted on 2002-03-12
17
Medium Priority
?
171 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

886 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