This content has been marked as final. Show 8 replies
Does the user also select a month? If not, do they always get the current month?
Dan, yes they will also have to select a month.
You can generate simple select boxes this way:
<CFLOOP INDEX="mo" FROM="1" TO="12"><OPTION VALUE="#mo#">#MonthAsString(mo)#</CFLOOP>
<CFLOOP INDEX="dd" FROM="1" TO="31"><OPTION VALUE="#dd#">#dd#</CFLOOP>
When you pass the value to your query, you can use CreateDate with the values for month and day (and year). You can add some validation since some months don't have 31 days.
Another way to do this is to display a visual calendar and have each date be a link to your query page, passing the date info as a URL parameter. See attached code.
Dan - just out of curiousity...why a textbox? I like the idea of the JS/Flash calendar (when there are no restrictions on using JS or Flash)...but if you're using plain' ol' HTML form elements, wouldn't a series of drop downs be better? A text input would require extra validation and parsing whereas dropdowns would require minimal validation and no string parsing.
Selects would be horrible. If you don't believe me, code yourself a form and then write the necessary client side validation to ensure that you don't submit an invalid date, like 2006-02-29.
One of my pet peeves is that all applications should be equally useable to keyboard pounders as they are to mouse pullers. That's my knock against the cfcalendar tag, you can't tab into it if you have an html form.
Regarding js calendars, there are lot's of them out there. They all work slightly differently.
<cfinput type="text" size="10" maxlength="10" value="#session.injurydate#"
message="Injury Date Must Be a Date" mask="9999-99-99"
name="injurydate" validate="date" validateat="onsubmit">
I've attached a nice little piece of code that I use EVERYWHERE... gets around your date validation functions, knows the difference between leap years etc.
Notice it submits the form on change? To get around having someone change the date and accidentally submit the form for processing I usually
<cfif (IsDefined("form.submit")) and (action is "submit for processing")>
>> process the form!
@dan - fair enough. for what it's worth, i've written the JS validation to handle the drop-downs (ensuring feb 30th can't be selected for example). i still find that easier to deal with than parsing a string (also bear in mind i'm not a big fan of cfform so i don't use cfinput). agreed on the usability aspect tho. would be nicer to keep things consistent for the keyboard pounders :)
@sean - with all due respect, the thought of having the form submit potentially multiple times in order to capture a single date value doesn't sit well with me at all. i'd rather code the client side validation to manipulate the "dobday" drop down based on the value of 'month' and/or 'year' or go an AJAX route. just my $0.02 (for whatever it's worth) :)