Arch Stanton
06-08-2004, 08:40 AM
Here are some functions I created today. They save you from having to make select boxes for dates. I normaly hate using select boxes because they can be a bit cumbersome, but when it comes to making sure you get valid data, nothing works better.
Month Select Box:
function monthSelect($fieldName,$selected) {
?>
<select name="<?=$fieldName?>">
<option value="">Choose Month</option>
<option value="01"<? if ($selected=="01") { echo " selected"; } ?>>January</option>
<option value="02"<? if ($selected=="02") { echo " selected"; } ?>>February</option>
<option value="03"<? if ($selected=="03") { echo " selected"; } ?>>March</option>
<option value="04"<? if ($selected=="04") { echo " selected"; } ?>>April</option>
<option value="05"<? if ($selected=="05") { echo " selected"; } ?>>May</option>
<option value="06"<? if ($selected=="06") { echo " selected"; } ?>>June</option>
<option value="07"<? if ($selected=="07") { echo " selected"; } ?>>July</option>
<option value="08"<? if ($selected=="08") { echo " selected"; } ?>>August</option>
<option value="09"<? if ($selected=="09") { echo " selected"; } ?>>September</option>
<option value="10"<? if ($selected=="10") { echo " selected"; } ?>>October</option>
<option value="11"<? if ($selected=="11") { echo " selected"; } ?>>November</option>
<option value="12"<? if ($selected=="12") { echo " selected"; } ?>>December</option>
</select>
<?
}
Day select box:
function daySelect($fieldName,$selected,$numDays) {
if (!$numDays) {
$numDays = 31;
}
?>
<select name="<?=$fieldName?>">
<option value="">Choose Date</option>
<?
for ($i = 1; $i <= $numDays; $i++) {
?>
<option<? if ($selected==$i) { echo " selected"; } ?>><?=$i?></option>
<?
}
?>
</select>
<?
}
Year select box:
function yearSelect($fieldName,$selected,$startYear,$numYears) {
if (!$startYear) {
$startYear = (date('Y')-1);
}
if (!$numYears) {
$numYears = 10;
}
?>
<select name="<?=$fieldName?>">
<option value="">Choose Year</option>
<?
for ($i = 0; $i < $numYears; $i++) {
$thisyear=$startYear+$i;
?>
<option<? if ($selected==$thisyear) { echo " selected"; } ?>><?=$thisyear?></option>
<?
}
?>
</select>
<?
}
No instructions on use at this time, I'm too busy, maybe later. For now, if you have any questions, just post em here.
Month Select Box:
function monthSelect($fieldName,$selected) {
?>
<select name="<?=$fieldName?>">
<option value="">Choose Month</option>
<option value="01"<? if ($selected=="01") { echo " selected"; } ?>>January</option>
<option value="02"<? if ($selected=="02") { echo " selected"; } ?>>February</option>
<option value="03"<? if ($selected=="03") { echo " selected"; } ?>>March</option>
<option value="04"<? if ($selected=="04") { echo " selected"; } ?>>April</option>
<option value="05"<? if ($selected=="05") { echo " selected"; } ?>>May</option>
<option value="06"<? if ($selected=="06") { echo " selected"; } ?>>June</option>
<option value="07"<? if ($selected=="07") { echo " selected"; } ?>>July</option>
<option value="08"<? if ($selected=="08") { echo " selected"; } ?>>August</option>
<option value="09"<? if ($selected=="09") { echo " selected"; } ?>>September</option>
<option value="10"<? if ($selected=="10") { echo " selected"; } ?>>October</option>
<option value="11"<? if ($selected=="11") { echo " selected"; } ?>>November</option>
<option value="12"<? if ($selected=="12") { echo " selected"; } ?>>December</option>
</select>
<?
}
Day select box:
function daySelect($fieldName,$selected,$numDays) {
if (!$numDays) {
$numDays = 31;
}
?>
<select name="<?=$fieldName?>">
<option value="">Choose Date</option>
<?
for ($i = 1; $i <= $numDays; $i++) {
?>
<option<? if ($selected==$i) { echo " selected"; } ?>><?=$i?></option>
<?
}
?>
</select>
<?
}
Year select box:
function yearSelect($fieldName,$selected,$startYear,$numYears) {
if (!$startYear) {
$startYear = (date('Y')-1);
}
if (!$numYears) {
$numYears = 10;
}
?>
<select name="<?=$fieldName?>">
<option value="">Choose Year</option>
<?
for ($i = 0; $i < $numYears; $i++) {
$thisyear=$startYear+$i;
?>
<option<? if ($selected==$thisyear) { echo " selected"; } ?>><?=$thisyear?></option>
<?
}
?>
</select>
<?
}
No instructions on use at this time, I'm too busy, maybe later. For now, if you have any questions, just post em here.