Ask a Jedi: Loading a Page with CFCALENDAR

Anthony asks a question about the CFCALENDAR tag:

I have a simple one... I think. I need to find out how to goto a URL when a date is selected using CFCalendar.

For instance, I choose Oct 17, I want to goto a page a date page with eq "2007-10-17"

I don't know flash, and have no idea how to accomplish what appears to be a simple operation.

Now technically I don't answer questions involving Flash Form stuff anymore. It was a fun feature, but in my opinion I'd use Flex 2 instead. But the calendar tag works in HTML forms as well so I thought I'd take a stab at this.

The docs for cfcalendar mention that it does indeed have an onChange event. However - you have to use ActionScript for this event. Now in theory - the calendar tag is just a Flex control. However - I had no idea what the control was, nor how to extra the current selected date. So I cheated. I know there is a getURL ActionScript function. This will fire off any URL, including a JavaScript one. So I began with this:

<cfform name="myform" action="test3.cfm"> <cfcalendar name="cal" onChange="getURL('javascript:test()')"> </cfform>

All this says is - when the date is selected, run the JavaScript function test (poorly named, I know). My test function then just does this:

<script> function test() { document.myform.submit(); } </script>

As you can see - it submits the form. You would then write code to say if exists, cflocation and pass along the value.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA