View Single Post
Old 09-13-2009, 02:16 AM   #1 (permalink)
Dave
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Default PHP-html select form not working as hoped...?

Good evening, everyone --

The following code is supposed to generate an html select form with a dropdown list of months, with the CURRENT MONTH pre-selected.

The dropdown list works, but the current month is not pre-selected as the default.

I've spent a lot of time on this, but have been unsuccessful. Thanks for taking a look!

-- Dave

PHP Code:
$arr_month = array(  =>  "January" 
                   
=>  "February"
                   
=>  "March"
                   
=>  "April"
                   
=>  "May"
                   
=>  "June"
                   
=>  "July"
                   
=>  "August"
                   
=>  "September"
                   
10 => "October"
                   
11 => "November"
                   
12 => "December"
                  
) ;

$today date"M-d-y"time() ) ;
echo 
"<div style = 'text-align: center'>\n" ;
echo 
"<h3>Today is $today</h3><hr>\n" ;

// create form containing date selection list 

echo "<form action = 'processform.php'
            method = 'POST'>\n" 
;

$todaymo date"n"time() ) ;

echo 
$todaymo "<br />" ;

echo 
"<label for 'datemo'></label>
      <select name = 'datemo' id = 'datemo'> \n" 

      
for ( 
$n $n <= 12 $n++ )
{
    echo 
"<option value = $n;
    if ( 
$todaymo == $n )
    {
        echo 
" selected" ;
    }
    echo 
"> $arr_month[$n] \n" ;
}
echo 
"</select>" 
Dave is offline  
Reply With Quote