Ouwe rakker |
|
Ik maakte hier altijd een functie voor die, aan de hand van een array, mij al die option elementen terug gaf.
<?php
function buildOptionArray($aArrayValue, $aArrayDisplay, $sCompare = '') {
$iArray = count($aArrayValue);
$sOutput = '';
for ($i = 0; $i < $iArray; $i++) {
$sOutput .= '<option value="' . $aArrayValue[$i] . '"' . ($aArrayValue[$i] == $sCompare ? ' selected="selected"' : '') . '>' . $aArrayDisplay[$i] . '</option>'."\n";
}
return $sOutput;
}
$selectedYear = 2008;
$selectedMonth = 6;
$selectedDay = 28;
?>
<select name="jaar">
<?php echo buildOptionArray(range(2000, date('Y') + 5), range(2000, date('Y') + 5), $selectedYear); ?>
</select>
<select name="maand">
<?php echo buildOptionArray(range(1, 12), range(1, 12), $selectedMonth); ?>
</select>
<select name="dag">
<?php echo buildOptionArray(range(1, 31), range(1, 31), $selectedDay); ?>
</select>
<?php function buildOptionArray($aArrayValue, $aArrayDisplay, $sCompare = '') { $iArray = count($aArrayValue); $sOutput = ''; for ($i = 0; $i < $iArray; $i++) { $sOutput .= '<option value="' . $aArrayValue[$i] . '"' . ($aArrayValue[$i] == $sCompare ? ' selected="selected"' : '') . '>' . $aArrayDisplay[$i] . '</option>'."\n"; } return $sOutput; } $selectedYear = 2008; $selectedMonth = 6; $selectedDay = 28; ?> <select name="jaar"> </select> <select name="maand"> <?php echo buildOptionArray (range(1, 12), range(1, 12), $selectedMonth); ?> </select> <select name="dag"> <?php echo buildOptionArray (range(1, 31), range(1, 31), $selectedDay); ?> </select>
|