Woyano Home - My Friends - My Topics - Inbox - Join - Login
bobsawyerdotcom's Woyano
Welcome to my world

Subscribe to
My Woyano network and Friends list!

Enter your email:

Multiple date dropdown function

Rate this:
By bobsawyerdotcom (Contact - View My Woyano)
Published Sun 18 Feb 2007, 5727 Views, 5 Comments

Multi Date Dropdown function
Handy for when you need to create multiple date dropdown fields in a form. Creates
dropdowns for year, month, and day with a unique identifier (passed from form) to
allow you to use multiple instances in a form.

usage: newDate('fieldname');

function newDate($date_ref) {
$year = "";
$month = "";
$day = "";

// year
echo '<select name="' . $date_ref . '_year">';
echo '<option value="">YY</option>';
for ($i = date('Y') -20; $i < date('Y') + 1; $i++) {
echo '<option value="' . $i . '">' . $i . '</option>';
}
echo '</select>';
// month
echo '<select name="' . $date_ref . '_month">';
echo '<option value="">MM</option>';
for ($m = 1; $m <= 12; $m++) {
echo '<option value="' . $m . '">' . $m . '</option>';
}
echo '</select>';
// day
echo '<select name="' . $date_ref . '_day">';
echo '<option value="">DD</option>';
for ($d = 1; $d <= 31; $d++) {
echo '<option value="' . $d . '">' . $d . '</option>';
}
echo '</select>';
}

This Item
Feature
Flag as Adult
Flag as Inappropriate
Category: Knowledge, Snippets, Technology
Tags: php, date, form, dropdown, function, script
Contributor
bobsawyerdotcom
Add to friends
Contact
View My Woyano
Share it
Link to this item:
Bookmark this item: RSS Feed

People who liked this item

    5 Comments

  1.  
    bobsawyerdotcom ~ 37 months ago
    0 votes thumbs up thumbs down
    Fixed formatting.
    [ reply ]
    1.  
      pauen ~ 37 months ago
      0 votes thumbs up thumbs down
      Do a google search for "Tigra Calendar". The tigra calendar pops up a calendar and lets you select the date. A little more code, but much, much, much easier for the user.
      [ reply ]
      1.  
        bobsawyerdotcom ~ 37 months ago
        0 votes thumbs up thumbs down
        Interestingly enough, anyone I've ever asked dislikes the popup calendar widget and prefers the 3-select-field widget such as this one. Which is why (a) I wrote it, and (b) I use it in all my sites. :-)
        [ reply ]
        1.  
          pauen ~ 37 months ago
          0 votes thumbs up thumbs down
          Personally, I prefer to type in my values, but not all user want to format their dates the same way. I've written date inputs both ways. If you've done the research, I'll believe it. All my sites have been internal applications, so my used base is pretty limited.
          [ reply ]
          1.  
            bobsawyerdotcom ~ 37 months ago
            0 votes thumbs up thumbs down
            No problem. To each his own, you know? :-)
            [ reply ]
            1.  
              22 votes thumbs up thumbs down
              This is my two cents...

                 
              Hey you know AdGuy always gets the last word! ;)

            Please Login to Add Your Comment   ..or..  

            Replying to comment by