Posted By

jakepaint on 08/02/07


Tagged

form dropdown calendar forms days months


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

depmed
kobylinski
hudge
g33kish
VladNovo


Month, Day Date Dropdown


 / Published in: PHP
 

  1. <form action="'.$_SERVER['PHP_SELF'].'" method="get">';
  2. $months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June','July', 'August', 'September', 'October', 'November', 'December');
  3. $weekday = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
  4. $days = range (1, 31);
  5. $years = range (2005, 2015);
  6.  
  7. //**********************************************
  8.  
  9. echo " Weekday: <select name='weekday'>";
  10. foreach ($days as $value) {
  11. echo '<option value="'.$value.'">'.$value.'</option>\n';
  12. } echo '</select><br />';
  13.  
  14. echo "Month: <select name='month'>";
  15. foreach ($months as $value) {
  16. echo '<option value="'.$value.'">'.$value.'</option>\n';
  17. } echo '</select><br />';
  18.  
  19. echo "Day: <select name='day'>";
  20. foreach ($days as $value) {
  21. echo '<option value="'.$value.'">'.$value.'</option>\n';
  22. } echo '</select><br />';
  23.  
  24. echo "Year: <select name='year'>";
  25. foreach ($years as $value) {
  26. echo '<option value="'.$value.'">'.$value.'</option>\n';
  27. }
  28. echo '</select><input type="submit" /></form>';

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: sheraaz on August 26, 2009

Nice piece of code but probably you would like to correct one small mistake for the weekday part. foreach ($days as $value) needs to be replaced by foreach ($weekday as $value) to populate the dropdown with weekdays..

You need to login to post a comment.