8 Replies Latest reply on Dec 1, 2006 12:48 PM by Charlie Griefer

    Creating drop down

      I am looking to create a dropdown that allows you to select a day of the month and when you click on the date take you to the query that will report the results for that particular day.
      Any help gratefully received.
        • 1. Re: Creating drop down
          Dan Bracuk Level 5
          Does the user also select a month? If not, do they always get the current month?
          • 2. Re: Creating drop down
            score1 Level 1
            Dan, yes they will also have to select a month.
            • 3. Re: Creating drop down
              dempster Level 1
              You can generate simple select boxes this way:

              <SELECT NAME="month">
              <CFLOOP INDEX="mo" FROM="1" TO="12"><OPTION VALUE="#mo#">#MonthAsString(mo)#</CFLOOP>
              <SELECT NAME="day">
              <CFLOOP INDEX="dd" FROM="1" TO="31"><OPTION VALUE="#dd#">#dd#</CFLOOP>

              When you pass the value to your query, you can use CreateDate with the values for month and day (and year). You can add some validation since some months don't have 31 days.

              Another way to do this is to display a visual calendar and have each date be a link to your query page, passing the date info as a URL parameter. See attached code.

              • 4. Re: Creating drop down
                Dan Bracuk Level 5
                My suggestion is to forget about drop downs. Either go with a text box or a javascript/flash calendar.
                • 5. Re: Creating drop down
                  Charlie Griefer
                  Dan - just out of curiousity...why a textbox? I like the idea of the JS/Flash calendar (when there are no restrictions on using JS or Flash)...but if you're using plain' ol' HTML form elements, wouldn't a series of drop downs be better? A text input would require extra validation and parsing whereas dropdowns would require minimal validation and no string parsing.
                  • 6. Re: Creating drop down
                    Dan Bracuk Level 5
                    Selects would be horrible. If you don't believe me, code yourself a form and then write the necessary client side validation to ensure that you don't submit an invalid date, like 2006-02-29.

                    One of my pet peeves is that all applications should be equally useable to keyboard pounders as they are to mouse pullers. That's my knock against the cfcalendar tag, you can't tab into it if you have an html form.

                    Regarding js calendars, there are lot's of them out there. They all work slightly differently.

                    Text boxes are simple. Here is how I usually code them. Bear in mind that do intranet, not internet programming, Among other things, I don't have to worry about users disabling their javascript.

                    <cfinput type="text" size="10" maxlength="10" value="#session.injurydate#"
                    message="Injury Date Must Be a Date" mask="9999-99-99"
                    name="injurydate" validate="date" validateat="onsubmit">
                    • 7. Creating drop down
                      sean69 Level 1
                      I've attached a nice little piece of code that I use EVERYWHERE... gets around your date validation functions, knows the difference between leap years etc.

                      Notice it submits the form on change? To get around having someone change the date and accidentally submit the form for processing I usually
                      <cfif (IsDefined("form.submit")) and (action is "submit for processing")>
                      >> process the form!
                      • 8. Re: Creating drop down
                        Charlie Griefer Level 1
                        @dan - fair enough. for what it's worth, i've written the JS validation to handle the drop-downs (ensuring feb 30th can't be selected for example). i still find that easier to deal with than parsing a string (also bear in mind i'm not a big fan of cfform so i don't use cfinput). agreed on the usability aspect tho. would be nicer to keep things consistent for the keyboard pounders :)

                        @sean - with all due respect, the thought of having the form submit potentially multiple times in order to capture a single date value doesn't sit well with me at all. i'd rather code the client side validation to manipulate the "dobday" drop down based on the value of 'month' and/or 'year' or go an AJAX route. just my $0.02 (for whatever it's worth) :)