Topic: How to have select box based on todays´date


riogrande    -- 03-31-2006 @ 3:13 PM
  I have three select boxes, day, month, year. I want the ´selected´ values to be today´s date. The days select box is 1-31, the month January-December, the year 2006-2020 How can I do this please?
<cfoutput>#DateFormat(Now())#,
#TimeFormat(Now())#</cfoutput>

<select name="day">
                <option>01</option>
                etc.
                <option>31</option>
              </select>
<SELECT name="month">
    <OPTION>January</OPTION>
    etc.
    <OPTION>December</OPTION>
  </SELECT>
  <select name="year">
     <option selected>2006</option>
      etc.
     <option>2020</option></select>


CJ    -- 03-31-2006 @ 3:20 PM
  <select name="day">
     <cfloop from="1" to="31" index="dd">
          <option value="#dd#"<cfif day(now()) EQ dd> selected="selected"</cfif>>#dd#</option>
     </cfloop>
</select>

that'll do your day.  based on that, you give month and year a shot Smile  

-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

This message was edited by CJ on 3-31-06 @ 9:18 PM


riogrande    -- 03-31-2006 @ 6:25 PM
  Thanks CJ I tried it out for day month and year with the following (complete) code but I get an error on the month select (The value of the attribute TO is invalid. The value cannot be converted to a numeric because it is not a simple value). Also I get an error on them all saying that (Variable I is undefined). Do I have to put the options in is that the problem? Thanks a lot

<tr><td class="label">
<select name="day" class="ftforminputsmall">
     <cfloop from="1" to="31" index="dd">
<option value="#dd#"<cfif day(now()) EQ i>
selected="selected"</cfif>#dd#</option> </cfloop>
</select> </td>
              
<td>
<select name="month">
     <cfloop from="January" to="December" index="dd">
    <option value="#dd#"<cfif month(now()) EQ i>
selected="selected"</cfif>#dd#</option></cfloop>
</select></td>
            
<td><select name="year">
<cfloop from="2006" to="2020" index="dd">
<option value="#dd#"<cfif year(now()) EQ i>
selected="selected"</cfif>#dd#</option></cfloop>
</select></td></tr>



mquack    -- 03-31-2006 @ 6:53 PM
  month(now()) returns the NUMERIC VALUE of the current month, and in your loop you have the TEXT VALUE.  Your month loop should be...

<cfloop from="1" to="12" index="dd">
</cfloop>

Also, your loop is using 'dd' as your index, and not 'i', so you need to change the IF statements to reflect that.


http://www.rachelqueensg.com

This message was edited by mquack on 3-31-06 @ 6:54 PM


CJ    -- 03-31-2006 @ 9:18 PM
  d'oH!

my bad on the 'i' thing.  editing my previous post to remove bone-headed error Smile  

-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com


riogrande    -- 04-01-2006 @ 12:47 PM
  Thanks a lot for the answers, changed the dd to i I am beginning to get my head around loops I will have a good session learning them.

The months in numbers is really annoying. I have search in the cfmx function reference docs and I can only seem to find one other function for months: Monthasstring which both seem to use numeric values. How do I make the 1 to 12 values in the month select change? Thanks a lot for any help
<select name="month">
     <cfloop from="1" to="12" index="i">
          <option value="#i#"<cfif month(now()) EQ i> selected="selected"</cfif>>#i#</option>
     </cfloop>
</select>




mquack    -- 04-01-2006 @ 1:01 PM
 

<cfset monthList =
"January,February,March,April,May,June,July,August,September,October,November,December"
/>

<cfloop list="#monthList#" index="m">
   <option value="#m#"<cfif monthAsString(month(now())) IS m> selected="selected"</cfif>>#m#</option>
</cfloop>



http://www.rachelqueensg.com


CJ    -- 04-01-2006 @ 8:25 PM
 
quote:

The months in numbers is really annoying. I have search in the cfmx function reference docs and I can only seem to find one other function for months: Monthasstring which both seem to use numeric values. How do I make the 1 to 12 values in the month select change? Thanks a lot for any help


you just answered the question you asked.

"...montasstring which ...seem to use numeric values."

don't you have numeric values (1-12)?

<cfloop from="1" to="12" index="i">
     #monthAsString(i)#<br />
</cfloop>

^ what's that give you?  can you use that function?



-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com


riogrande    -- 04-03-2006 @ 5:41 PM
  Thanks cj and mquack:I used your way mquack as the <cfloop from="1" to="12" index="i">
     #monthAsString(i)#<br />
</cfloop>
still gave me a list of 1-12 numbers

This message was edited by riogrande on 4-3-06 @ 5:43 PM


mquack    -- 04-03-2006 @ 6:27 PM
  rio-

Just to clarify, my example does NOT use a 1-12 loop.  I created a list with the months in it and then looped thru that list.

http://www.rachelqueensg.com


EasyCFM.COM ColdFusion Forums : http://www.easycfm.com/forums
Topic: http://www.easycfm.com/forums/viewmessages.cfm?Forum=12&Topic=9039