|
|
|
This is a simple select element with month notations. You can translate the names for local using. Based on the current date the actual month is selected.
| <?php
$curr_month = date("m");
$month = array (1=>"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$select = "<select name=\"month\">\n";
foreach ($month as $key => $val) {
$select .= "\t<option val=\"".$key."\"";
if ($key == $curr_month) {
$select .= " selected>".$val."\n";
} else {
$select .= ">".$val."\n";
}
}
$select .= "</select>";
echo $select;
?> | | |
|
| Tag content retrieval from websites with preg_match Categories : PHP, Regexps, Arrays, HTML and PHP | | | Creates three SELECT form fields: Month, Day, and Year. You give it a string which will be used to make the name for the three fields, and a number of seconds to use as the default date. If you give it blank for this value, the current date is used. Categories : HTML and PHP, PHP, Date Time | | | If you want to create select buttons featuring current date this example will show you how... Categories : Date Time, HTML and PHP, PHP | | | How to pass an array from one PHP Script to another via an HTML form Categories : PHP, HTML and PHP, Arrays | | | dynamic table columns Categories : PHP, HTML and PHP, Arrays, Databases, MySQL | | | Website colour changer Categories : PHP, HTML and PHP, Date Time | | | Print out array key => value in colored HTML Categories : PHP, Arrays, HTML and PHP | | | Form Submission Using Array's Categories : PHP, HTML and PHP, Beginner Guides, Arrays | | | CALENDAR - easy calendar-navigation with PHP Categories : PHP, Date Time, HTML and PHP, Calendar | | | This script contains 2 functions: 1 to create html select object based on your own customer date format entry- "M d Y h:i.... etc". The second function processes the select object on submit back to unix time. Categories : PHP, Calendar, Date Time, HTML and PHP | | | Parsing html tags with php. Get an array from this function Categories : PHP, HTML and PHP, Arrays, Tag Extractors | | | Kewl Date Example Categories : PHP, HTML and PHP, Date Time, CSS, Beginner Guides | | | Convert date's in YYYY-MM-DD (i.e. mysql format) into PHP3 timestamps. Also Find the difference in days between two PHP3 timestamps. Categories : HTML and PHP, PHP, MySQL, Date Time | | | Simple PHP control CSS Calender Categories : PHP, HTML and PHP, Calendar, Date Time, CSS | | | enhanced date picker with jcript checking for a dynamic date input Categories : PHP, Java Script, Date Time, Calendar, Arrays | |
| | | | James Salinas wrote : 1262
good code, but you can shorten that by doing this:
foreach($month as $key => $val) {
$select .= "\t<option val=\"$key\"";
if($key == $curr_month) {
$select .= " selected";
}
$select .= ">$val\n";
}
*also, to try to keep w3c compliant, should use
$select .= " selected=\"selected\"";
instead ;)
| | | | Olaf Lederer wrote :1270
it`s from the w3 website:
<SELECT multiple size="4" name="component-select">
<OPTION selected value="Component_1_a">Component_1</OPTION>
<OPTION selected value="Component_1_b">Component_2</OPTION>
<OPTION>Component_3</OPTION>
<OPTION>Component_4</OPTION>
<OPTION>Component_5</OPTION>
<OPTION>Component_6</OPTION>
<OPTION>Component_7</OPTION>
</SELECT>
do you know a diff. one?
Olaf
| |
|
|
|