Jump to content

PHP Drop Down Calendar, Want it to be "sticky"


tworld

Recommended Posts

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']);

     

      ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.