I have made myself a “To Do” list which I add refinements to every once in a while. I have the following code for selecting the date for which I want the task to be active. Most tasks that I add are for the current date, but sometimes I want to included something to show up in the future.
So what I would like to do (and can’t figure out how) is to have the current date showing on the drop-down menu by default, until I change it if needed.
I’d be quite happy with just some hints as to what my strategy should be so that I can try to figure out the code. Thanks.
<select name="month">
<?php $month_name = array(January, February, March, April, May, June, July, August, September, October, November, December);
for ($i=0; $i<12; $i++) {
$month_number = $i + 1;
if ($month == $month_number) {
$selected = "selected=\\"selected\\"";
} else {
$selected = "";
}
print ("<option value=\\"$month_number\\" $selected>$month_name[$i]</option>");
}
?>
</select>
<select name="day">
<?php
for ($i=1; $i<=31; $i++) {
if ($day == $i) {
$selected = "selected=\\"selected\\"";
} else {
$selected = "";
}
print("<option value=\\"$i\\" $selected>$i</option>");
}
?>
</select>
<select name="year">
<option value="<?php print $current_year; ?>"
<?php
if ($year == "$current_year") {
print(" selected=\\"selected\\" >");
} else {
print(">");
}
?>
<?php print $current_year; ?></option>
<option value="<?php print $next_year; ?>"
<?php
if ($year == "$next_year") {
print(" selected=\\"selected\\">");
} else {
print(">");
}
?>
<?php print $next_year; ?></option>
</select><br />