Page 1 of 1

Month Drop Down Menue Code ??? Setting Current Month

Posted: Mon Nov 16, 2009 12:52 am
by edawson003
I am using the below code to generate a drop down menu for month. How can I modify this so that the current month is the default selection?

Code: Select all

<?php
$options = array(0=>'00', 1=>'01',2=>'02',3=>'03',4=>'04',5=>'05',6=>'06',7=>'07',8=>'08',9=>'09',10=>'10',11=>'11',12=>'12'); 
$selectedValue = isset($_POST['month']) ? $_POST['month'] : '';
 echo '<select class=clp name="month">' . "\n";
 foreach($options as $key=>$value) {
     echo '<option value="' . $key. '" ' . ($key== $selectedValue ? 'selected="selected"' : '') . '>' . $value . '</option>' . "\n";
 }
 echo '</select>';
 ?>

Re: Month Drop Down Menue Code ??? Setting Current Month

Posted: Mon Nov 16, 2009 2:23 am
by requinix

Code: Select all

$selectedValue = isset($_POST['month']) ? $_POST['month'] : '';
How about setting the $selectedValue to be the current month? In fact, you could probably set $_POST["month"] to be date("n").

Re: Month Drop Down Menue Code ??? Setting Current Month

Posted: Mon Nov 16, 2009 8:44 pm
by edawson003
K. Thanks. I went with setting,

Code: Select all

$_POST['month'] = date(m,time());
and it works fine. Thx for the suggestion