Submit CFCALENDAR onchange
I'm building an application that needs a calendar picker tool and I decided to check out the CFCALENDAR form control. It turns out that since it is a flash component, the onchange event uses ActionScript rather than JavaScript. This proved a bit frustrating for me since I knew zero ActionScript going into this and I was initially unable to find any help online. I eventually came across a page, Passing Variables Around - Flash to HTML and Back that talked about how to emulate a METHOD="GET" submit in ActionScript. I then learned about how AS names fields and some basic date functions and came up with the following code:
The key was to reference the field name selectedDate rather than TestDate, otherwise you keep passing the original date. I then needed to reassemble the date into a format that ColdFusion would understand using the getMonth, getDate, and getFullYear functions. Also I needed to add one to the result of getMonth since ActionScript starts counting months at 0 instead of 1.
<cfparam name="TestDate" default="#Now()#">
<cfoutput>#TestDate#</cfoutput>
<cfform name="TestForm" id="TestForm" action="cfcalendar.cfm">
<cfcalendar name="TestDate" selecteddate="#DateFormat(TestDate,'mm/dd/yyyy')#"
onchange="getURL('cfcalendar.cfm?TestDate=' + (TestDate.selectedDate.getMonth()+1) + '/' +
TestDate.selectedDate.getDate() + '/' + TestDate.selectedDate.getFullYear());">
</cfform>
The key was to reference the field name selectedDate rather than TestDate, otherwise you keep passing the original date. I then needed to reassemble the date into a format that ColdFusion would understand using the getMonth, getDate, and getFullYear functions. Also I needed to add one to the result of getMonth since ActionScript starts counting months at 0 instead of 1.
Labels: ColdFusion

