I have currently set up a select drop down menu that does three things:
- By default it picks a date 48 hours in the future and the current month
- To prevent a date selected in the past it only shows the selected date until the end of the current month
- Another limitation the system has is that it shows all the months until the end of the calendar year
But now I have a problem! Let me use this example to explain my difficulty
- At the time of writing a date of 23 September is available by default. No other dates are available before 23 September
- The user has the option selecting dates from 23 September to 31 September
- The user also has the option of selecting months from September to December
The problem now arises when the user tries to select a date from a different month. The date limitation still exists! So if I switch to October I can only select dates from 23 October to 31 October. Which is wrong cos I want to select dates from 1 October to 31 October.
How can I refresh the drop down in real-time to update the date entry when the user switches to another month?
Here is the code I'm using right now:
<label for="date"><?php echo __('Pickup Date') ?> <span>*</span></label>
<?php
$curr_day = date('j', strtotime('+ 48 hours'));
$day = range (1, 31);
$day = array_slice($day, $curr_day-1);
$select = "<select name="day">
";
foreach ($day as $key => $val) {
$select .= "<option val="".$key.""";
if ($key == $curr_day) {
$select .= " selected="selected">".$val."</option>
";
} else {
$select .= ">".$val."</option>
";
}
}
$select .= "</select>";
echo $select;
?>
:
<?php
$curr_month = date("m");
$month = array (1=>"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$month = array_slice($month, $curr_month-1);
$select = "<select name="month">
";
foreach ($month as $key => $val) {
$select .= "<option val="".$key.""";
if ($key == $curr_month) {
$select .= " selected="selected">".$val."</option>
";
} else {
$select .= ">".$val."</option>
";
}
}
$select .= "</select>";
echo $select;
?>
Many thanks in advance!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…