You are here: Re: Populating "Month" Dropdown Menu « All PHP « IT news, forums, messages
Re: Populating "Month" Dropdown Menu

Posted by Justin Koivisto on 01/19/06 17:26

cover wrote:
> I can get the current month to display in a text box by inserting
> value="<? print strftime("%B"); ?>"> into the code for that
> particular text box on a form but how can I populate a drop down with
> names of all the months with the current one being 'default' as it
> would be in the text box example? TIA

/**
* generates an HTML select element for the month
*
* @param string $name The name of the HTML field
* @param int $this_month=-1 The month number to have selected. If not
supplied, current month is used. If 0, no month is selected.
* @return string
*/
function get_html_select_month($name='',$this_month=-1){
if(empty($name)) $name='month';
if($this_month==-1) $this_month=date('n');
$months=range(1,12);
$str='<select name="'.$name.'">'."\n";
foreach($months as $month){
$str.=' <option value="'.$month.'"';
if($month==$this_month) $str.=' selected="selected"';
$str.='>'.date('F',mktime(0,0,0,$month,1,2006)).'</option>'."\n";
}
$str.='</select>'."\n";
return $str;
}


--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация