Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default value for CFSELECT 1

Status
Not open for further replies.

Benbunny

Programmer
Mar 19, 2001
18
0
0
HK
Hi all,

I'm a beginner in ColdFusion. I would like to ask out a simple question. Please help me!

<cfselect name=&quot;selectmonth&quot; size=1 multiple=&quot;no&quot;>
<option value=&quot;01&quot;>January
<option value=&quot;02&quot;>Feburary
<option value=&quot;03&quot;>March
<option value=&quot;04&quot;>April
<option value=&quot;05&quot;>May
<option value=&quot;06&quot;>June
<option value=&quot;07&quot;>July
<option value=&quot;08&quot;>August
<option value=&quot;09&quot;>September
<option value=&quot;10&quot;>October
<option value=&quot;11&quot;>Noveber
<option value=&quot;12&quot;>December
</cfselect>

By running the cfm file, I cannot default the current month.
It just show the 1st choice. How can I do it?
Please give me a hand. Thanks a lot.
 
HI BenBunny,

This will do it. It's the same as HTML really:

<cfselect name=&quot;selectmonth&quot; size=1 multiple=&quot;no&quot;>
<option value=&quot;01&quot;>January
<option value=&quot;02&quot;>Feburary
<option value=&quot;03&quot;>March
<option value=&quot;04&quot;>April
<option value=&quot;05&quot; Selected >May
<option value=&quot;06&quot;>June
<option value=&quot;07&quot;>July
<option value=&quot;08&quot;>August
<option value=&quot;09&quot;>September
<option value=&quot;10&quot;>October
<option value=&quot;11&quot;>Noveber
<option value=&quot;12&quot;>December
</cfselect>


So May would automatically be selected.

This little gizmo is kinda nice, It creates the month Select automatically and makes this month be choosen. Check it out:

<cfselect name=&quot;selectmonth&quot; size=1 multiple=&quot;no&quot;>
<CFLOOP index=&quot;mnth&quot; from=&quot;1&quot; to =&quot;12&quot;>
<CFOUTPUT>
<Option Value=&quot;#mnth#&quot; <CFIF #Month(NOW())# is &quot;#mnth#&quot;>Selected</CFIF> >#DateFormat(CreateDate(Year(NOW()),mnth,Day(NOW())),&quot;MMMM&quot;)#
</CFOUTPUT>
</CFLOOP>
</cfselect>



Hope it helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top