Skip to main content
Inspiring
January 12, 2009
Question

Can you frce a date range

  • January 12, 2009
  • 3 replies
  • 572 views
I am trying to force a user to only enter a date between the range of 01/01/2009 to 12/31/2010. Is there a way to do this in a standard <cfinput>? I attempted to use the range attribute, but it does not like the format.
    This topic has been closed for replies.

    3 replies

    Inspiring
    January 12, 2009
    In addition to the options above, you could also employ an Ajax library, such as jQuery (jquery.com), to help handle this for you. jQUery has a UI library (separate from the standard jQuery library) that has a Date Picker component. You can use the date picker and set it so that it restricts the dates available.

    Someone posed this question on another site/list and had a good answer on how to do it with jQuery:
    http://stackoverflow.com/questions/389743/how-to-limit-days-available-in-jquery-ui-date-picker
    Inspiring
    January 12, 2009
    You can write a js function and call it with the onSubmit attribute of your cfform tag.
    Known Participant
    January 12, 2009
    I tried doing this as well.

    In the end I created two drop down boxes - one for day of month and one for month/year (I also had the problem of using european dates so drop down boxes avoided some possible errors)

    (Apologies for the lack of correct CF below but I should really be busy!)

    <select><option value="01">1st</option>...</select>
    <cfset curMonth = createDate(2009-01-01)>
    <cfselect><cfloop from 0 to 23 index i>
    <option value eq "#dateFormat(curMonth, yyyy-mm-)#">
    <dateAdd(m, #i#, curMonth)>
    </cfloop></cfselect>

    date = #monthField##dateField# e.g. "2009-01-""03"
    JatrixAuthor
    Inspiring
    January 12, 2009
    That would work, but is there a way to do it in a <cfinput> box? I only want to use a drop down aas a last resort.