jor133d Posted September 27, 2007 Share Posted September 27, 2007 I am trying to modify some code so that the days dropdown has the correct amount of days for each month( Jan - 31 days, Feb 28, etc). I managed to get it so the correct days appear however it lists all the days. http://www.glitzphotography.com/date/dateform.php Can someone help me get this to work properly? Thanks! <?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">'; foreach ($months as $key => $value) { $num = cal_days_in_month(CAL_GREGORIAN, $key, 2007); for ($day = 1; $day <= $num; $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>'; $num = cal_days_in_month(CAL_GREGORIAN, 11, 2007); // 31 echo "There was $num days"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/70934-days-based-on-months/ Share on other sites More sharing options...
wildteen88 Posted September 27, 2007 Share Posted September 27, 2007 If want the days drop down menu to adapt so the correct number of days are displayed for the selected the month then you'll need to use javascript to repopulate the days list, or submit the form when the month drop down box has changed. Quote Link to comment https://forums.phpfreaks.com/topic/70934-days-based-on-months/#findComment-356586 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.