Hi,
I am trying to convert my code for month and day drop down menus to be dynamic. What I want is, instead of having 31 days in every month, have them have the actual days they have, so if the user clicks Feb, 28 days will show and so on. Also, I'm trying to get leap year to work too, but with no luck... any help or direction pointing would be greatly appreciated.
Thanks,
Erik
<?php
function make_calendar_pulldowns($m = NULL, $d = NULL, $y = NULL) // This function makes three pull-down lists
// for the months, days, and years.
{
// Make the months array.
$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September',
'October', 'November', 'December');
// Make the months pull-down list
echo '<select name="month">';
foreach ($months as $key => $value)
{
echo "<option value=\"$key\"";
if ($key == $m) { echo ' selected="selected"'; }
echo ">$value</option>\n";
}
echo '</select>';
// Make the days pull-down list
echo '<select name="day">';
for ($day = 1; $day <= 31; $day++)
{
echo "<option value=\"$day\"";
if ($day == $d) { echo ' selected="selected"'; }
echo ">$day</option>\n";
}
echo '</select>';
// Make the years pull-down list
echo '<select name="year">';
for ($year = 2005; $year <= 2015; $year++)
{
echo "<option value=\"$year\"";
if ($year == $y) { echo ' selected="selected"'; }
echo ">$year</option>\n";
}
echo '</select>';
} // End of the function definition.
// Create the form tags.
echo '<h1 id="mainhead">Select a Date:</h1>
<p><br /></p><form action="dateform.php" method="post">';
// Call the function.
$dates = getdate();
make_calendar_pulldowns($dates['mon'], $dates['mday'], $dates['year']);
// End of form.
echo '</form><p><br /></p>';
// Print the current date and time
echo '<p>Today is ' . date('l') . '. The current time is ' . date('g:i a') . '.</p>';
?>
Here is my new arrays that I am using:
// Make the months array.
$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
// Make the days array
$days = array(1 => 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);