09-13-2009, 02:16 AM
|
#1 (permalink)
|
|
The Acquainted
Join Date: Apr 2008
Posts: 110
Thanks: 97
|
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( 1 => "January"
, 2 => "February"
, 3 => "March"
, 4 => "April"
, 5 => "May"
, 6 => "June"
, 7 => "July"
, 8 => "August"
, 9 => "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 = 1 ; $n <= 12 ; $n++ )
{
echo "<option value = $n" ;
if ( $todaymo == $n )
{
echo " selected" ;
}
echo "> $arr_month[$n] \n" ;
}
echo "</select>" ;
|
|
|
|