Solved

How to add functionality to this select box?

Posted on 2002-03-12
17
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 
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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

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

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…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

623 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