1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4. <head>
5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6. <title>Date Menus</title>
7. </head>
8. <body>
9. <?php // Script 10.2 - menus2.php
10. /* This script defines and calls a function that takes arguments. */
11.
12. // This function makes three pull-down menus for the months, days, and years.
13. // This function requires two arguments be passed to it.
14. function make_date_menus($start_year, $num_years) {
15.
16. // Array to store the months:
17. $months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
18.
19. // Make the month pull-down menu:
20. print '<select name="month">';
21. foreach ($months as $key => $value) {
22. print "\n<option value=\"$key\">$value</option>";
23. }
24. print '</select>';
25.
26. // Make the day pull-down menu:
27. print '<select name="day">';
28. for ($day = 1; $day <= 31; $day++) {
29. print "\n<option value=\"$day\">$day</option>";
30. }
31. print '</select>';
32.
33. // Make the year pull-down menu:
34. print '<select name="year">';
35. for ($y = $start_year; $y <= ($start_year + $num_years); $y++) {
36. print "\n<option value=\"$y\">$y</option>";
37. }
38. print '</select>';
39.
40. } // End of make_date_menus() function.
41.
42. // Make the form:
43. print '<form action="" method="post">';
44. make_date_menus(2009, 15);
45. print '</form>';
46.
47. ?>
48. </body>
49. </html>