tworld Posted August 4, 2008 Share Posted August 4, 2008 I am making a register type of form that has a drop down calendar selection. In the event of an error on another part of the page (such as a bad e-mail) I would like for a user not to have to re-select the date. Can someone help me make this sticky? One other note is that the calendar is set to show "today's date" with the getdate() function at the bottom. But once a user selects a date I would like it to stay selected. The reason it has "2" on the variables is because it is the second calendar in the total form. <?php //This function makes 3 pulldown menus for the months, days, and years. function make_calendar_pulldowns2($m2 = NULL, $d2 = NULL, $y2 = NULL) { //Make the months array. $months2 = array (1 => 'January','February','March','April','May','June','July','August','September','October','November','December'); //Make the months into a pulldowm. echo '<select name="month2">'; foreach ($months2 as $key => $value) { echo "<option value=\"$key\""; if ($key == $m2); { //Preselect. echo ' selected="selected"'; } echo ">$value</option>\n"; } echo '</select>'; //Make the days pull-down menu. echo '<select name="day2">'; for ($day2 = 1; $day2 <= 31; $day2++) { echo "<option value=\"$day2\""; if ($day2 == $d2) { //Preselect. echo ' selected="selected"'; } echo ">$day2</option>\n"; } echo '</select>'; //Make the years pull-down menu. echo '<select name="year2">'; for ($year2 = 2008; $year2 <= 2022; $year2++) { echo "<option value=\"$year2\""; if ($year2 == $y2) { //Preselect. echo ' selected="selected"'; } echo ">$year2</option>\n"; } echo '</select>'; }//End of Function Definition //Get today's date and call the function. $dates2 = getdate(); make_calendar_pulldowns ($dates2['mon'],$dates2['mday'],$dates2['year']); ?> Link to comment https://forums.phpfreaks.com/topic/118004-php-drop-down-calendar-want-it-to-be-sticky/ Share on other sites More sharing options...
centerwork Posted August 4, 2008 Share Posted August 4, 2008 What I will usually do is add an if statement that says something like this: if($submit=="submit") { echo 'value="'.$mo.'"; } Inside of the input tag. I am not sure if this will work for you or not. Link to comment https://forums.phpfreaks.com/topic/118004-php-drop-down-calendar-want-it-to-be-sticky/#findComment-607072 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.