Skip navigation
Currently Being Moderated

Using CFINPUT dateField with onChange

Sep 29, 2006 5:28 AM

I imagine this is easy, but have tried to search here as well as Google it and have come up empty.

I have a CFINPUT dateField control that is OK when my form loads, but then I want the control to capture a new date selection from the user and update the form. I believe the onChange event is used to process this, but I don't know how to code it so that it will refresh the form using the new date and keep the user's date selection.
  • Currently Being Moderated
    Oct 19, 2006 6:24 PM   in reply to DLAH
    Why don't you just use:

    <cfinput type="date..." name="test" onchange="{_root.formfieldtochange.text=_root.test.text;}">
    <cfinput type="text" name="formfieldtochange">

    Whenever you update the datepicker, it will automatically change the value in the other field.
    Mark as:
  • Currently Being Moderated
    Aug 29, 2010 6:38 AM   in reply to mcadle

    The onChange event doesn't work with cfinput type datefield using CFML in a plain HTML form.


    In Flash form and flex, the onChange event works perfectly, i.e. whenever you choose a new date, the event fires.


    In HTML form, when you choose a new date from the datefield, the event doesn't fire. You have to select the new date, then click into the textbox and hit the enter key. Then only it fires the onChange event. Very strange indeed!


    Any ideas how to get this feature working or is it a bug in CF itself?



    Mark as:
  • Currently Being Moderated
    Aug 29, 2010 7:01 AM   in reply to YogeshM

    From my reading of the HTML spec, it's not a bug, it's how the onchange event works.  The spec says:


    The onchange event occurs when a control loses the input focus and its value has been modified since gaining focus


    (My emphasis).




    When changing the control's value via script, the control never gets the focus, so implicitly never loses the focus, which is a prereq for the onchange event to fire.


    The same thing happens if one changes a normal form input control via script.  No event fires.




    Mark as:
  • Currently Being Moderated
    Aug 30, 2010 4:36 AM   in reply to Adam Cameron.

    Thanks Adam!


    I've come across a possible workaround to this issue.


    You can find it here: n-datefieldchange-question


    Hope this helps others as well.



    Mark as:
  • Currently Being Moderated
    Aug 30, 2010 4:52 AM   in reply to YogeshM

    I do however have an issue with the cfinput type datefield.


    How do you disable Saturdays and Sundays?


    In Flash form and Flex, we only use disabledDays=[0,6]


    For example,




              mask="dd/mm/yyyy" width="50"
              onFocus="valuationDate_txt.disabledDays = [0,6];">


    How do we make the disabledDays=[0,6] work with the cfinput type datefield?


    Thanks and regards.

    Mark as:
  • Currently Being Moderated
    Aug 30, 2010 5:22 AM   in reply to YogeshM

    I have no idea, but I would start a new topic rather than tack it on to this one, because that question has nothing to do with the subject line.  People who might not know about onchange events but do know about enabling/displaying specific days will perhaps not see your question, as they might not bother reading it.




    Mark as:
  • Currently Being Moderated
    Jun 6, 2012 11:03 PM   in reply to DLAH

    This may not be the most elegant solution out there, but it works okay.


    ====== Javascript Code ======

    i = 0;

    function doSubmit(caldate) {


    if (i>1) {

    window.location = "index.cfm?caldate=" + document.getElementById('caldate').value;





    =====CFML Code ======

    <cfform ... typical code here ....>

    <cfinput type="datetime" id="caldate" ...typical code here .... />

    <cfajaxproxy bind="javaScript:doSubmit({caldate})">




    What this does is fires doSubmit each time the form controls are touched or the value is modified.  When this happens, it will increment i.  You will fire doSubmit twice (once to open the calendar and then once when a date is actually selected).  So you want to fire when i = 2 or when i > 1.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points