Skip to main content
Inspiring
December 17, 2008
Question

cfselect and time

  • December 17, 2008
  • 1 reply
  • 426 views
Hello,
I would like to get some tips on the best way to accomplish what I am trying. Obviously my method is not exactly working the way I wanted it too. I have select boxes for the user to enter the time. I just need some ideas on either a new method or a fix.
<cfselect name="eventstarthour" id="eventstarthour" >
<option value="" selected>Select Hour</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</cfselect>
<cfselect name="eventstartminute" id="eventstartminute">
<option value="" selected>Select Minute</option>
<option value="00">00</option>
<option value="30">30</option>
</cfselect>


I have this to set things up to be entered into a mysql db later, which works fine if the user actually selects a time, but fails if they do not select anything which is ok if they do not need to select a time as it will not always be necessary. I just need a way to handle when a user does not select a time, that field will just need to remain a NULL value.

<cfif isdefined("form.eventstarthour")>
<cfset Session.eventstarttime = '#form.eventstarthour#:#form.eventstartminute#'>
<cfelse>
<cfset Session.eventstarttime = "">
</cfif>
<cfif isdefined("form.eventendhour")>
<cfset Session.eventendtime = '#form.eventendhour#:#form.eventendminute#'>
<cfelse>
<cfset Session.eventendtime = "">
</cfif>

What is a good way of handling user input of time? I thought about doing it this way, but I dont like how long the list would be once I added in the half hour options.

<cfselect name="eventstarthour" id="eventstarthour" >
<option value="" selected>Select Hour</option>
<option value="1:00">1:00A</option>
<option value="2:00">2:00A</option>
<option value="3:00">3:00A</option>
<option value="4:00">4:00A</option>
<option value="5:00">5:00A</option>
<option value="6:00">6:00A</option>
<option value="7:00">7:00A</option>
<option value="8:00">8:00A</option>
<option value="9:00">9:00A</option>
<option value="10:00">10:00A</option>
<option value="11:00">11:00A</option>
<option value="12:00">12:00P</option>
<option value="13:00">1:00P</option>
<option value="14:00">2:00P</option>
<option value="15:00">3:00P</option>
<option value="16:00">4:00P</option>
<option value="17:00">5:00P</option>
<option value="18:00">6:00P</option>
<option value="19:00">7:00P</option>
<option value="20:00">8:00P</option>
<option value="21:00">9:00P</option>
<option value="22:00">10:00P</option>
<option value="23:00">11:00P</option>
<option value="00:00">12:00P</option>
</cfselect>
    This topic has been closed for replies.

    1 reply

    BKBK
    Community Expert
    Community Expert
    December 17, 2008
    An idea: Use hour, minute and the AM/PM flag