Create select options and get the current values for month and date
<select name="year"><?=options(date('Y'),1900)?></select>
<select name="month"><?php echo
date('m');?><?=options(1,12,'callback_month')?></select>
<select name="day"><?php echo date('d');?><?=options(1,31)?></select>
PHP
function options($from,$to,$callback=false)
{
$reverse=false;
if($from>$to)
{
$tmp=$from;
$from=$to;
$to=$tmp;
$reverse=true;
}
$return_string=array();
for($i=$from;$i<=$to;$i++)
{
$return_string[]='<option
value="'.$i.'">'.($callback?$callback($i):$i).'</option>';
}
if($reverse)
{
$return_string=array_reverse($return_string);
}
return join('',$return_string);
}
function callback_month($month)
{
return date('m',mktime(0,0,0,$month,1));
}
What should i make to get the current month and date in the corresponding
dropdowns as starting values, as it is the case with years (2013).
No comments:
Post a Comment