Generate a dropdown with months in a year





11
Date Submitted Mon. Sep. 18th, 2006 5:02 AM
Revision 1 of 1
Helper nothingless
Tags forcodegrrl | forms | PHP
Comments 0 comments
The below code will generate a form dropdown for all 12 months, with the current month selected. Handy for those date pickers!
<select name="start_month">
<?php
global $LOC;
$current_time_m = $LOC->decode_date('%m', $LOC->now);

for ($i = 1; $i <= 12; $i++) {
   echo "<option value='$i-'";
if ($i == $current_time_m) { echo " selected='selected'"; }
$month_text = date("F", mktime(0, 0, 0, $i+1, 0, 0, 0));
   echo ">$month_text</option>
"
; } ?>
</select>
 

Comments

There are currently no comments for this snippet.

Voting