Page 1 of 1
months issue
Posted: Mon May 22, 2006 2:56 am
by itsmani1
I want to populate my listbox with months like this
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
how to do this?
any idea?
thanks much.
Posted: Mon May 22, 2006 3:00 am
by bdlang
Store the month names in an array and loop over them with
foreach() to create the elements you want.
Posted: Mon May 22, 2006 6:01 am
by itsmani1
thanks much,
let me try
Posted: Mon May 22, 2006 6:21 am
by Chris Corbyn

I thought you had a moth infestation for a moment there

Posted: Mon May 22, 2006 9:17 am
by opensme
Code: Select all
<?php
echo '<select name="month">';
$months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct ', 'Nov', 'Dec');
foreach ($months as $month) {
// Set select box to current month
if (date("M") == $month) {
echo '<option value="'.$month.'" selected>'.$month.'</option>';
}
else {
echo '<option value="'.$month.'">'.$month.'</option>';
}
}
echo '</select>';
?>