943,147 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 469
  • PHP RSS
Feb 9th, 2010
0

correction of code plz

Expand Post »
Hi guys, can any one correct my coding please, I want to create a form which ask for a month(dropdown) and year on input and onsubmit it checks if fields are valued and if so submit a page with teh calender of that month. Saterdays and sundays should have different colors, plus the user can choose anotehr month in the page of the month chosen.. This is what I've tried on my own and i just need direction , thank u...

PHP Syntax (Toggle Plain Text)
  1. <html >
  2. <head>
  3. <title>Exercise1</title>
  4. <script type="text/javascript" src="jquery/jquery/jquery.js">
  5. <script type="text/javascript">
  6. function valid()
  7. {
  8. var field = "";
  9. if (!$('[name=month]').val()) field += 'month\n';
  10. if (!$('[name=year]').val()) field += 'year\n';
  11.  
  12. if (field != "") {
  13. alert ('Please select the value\n'+field);
  14. return false;
  15. }
  16. return true;
  17. }
  18.  
  19. </script>
  20. <?php
  21. if (!checkdate($_POST[month], 1, $_POST[year])) {
  22. $calArray = getdate();
  23. $month = $calArray['mon'];
  24. $year = $calArray['year'];
  25. } else
  26. {
  27. $month = $_POST[month];
  28. $year = $_POST[year];
  29. }
  30. $start = mktime (12, 0, 0, $month, 1, $year);
  31. $firstDayArray = getdate($start);
  32.  
  33. $months = Array("January", "February", "March", "April", "May",
  34.  
  35. "June", "July", "August", "September", "October", "November", "December");
  36.  
  37.  
  38. for ($x=1; $x <= count($months); $x++) {
  39.  
  40. print "\t<calender=\"$x\"";
  41.  
  42. print ($x == $month)?" SELECTED":"";
  43.  
  44. print ">".$months[$x-1]."\n";
  45.  
  46. }
  47. for ($x=0; $x<=2010; $x++) {
  48. print "\t<calender";
  49. print ($x == $year)?" SELECTED":"";
  50. print ">$x\n";
  51. }
  52. ?>
  53. <style>
  54. </style>
  55. </head>
  56. <body>
  57. <h3>Calender</h3>
  58. <form method="post" name="form" action="exercise2.php" onsubmit="return valid()">
  59. <select name="month"><option value=""></option>
  60. <option value="1">January</option>
  61. <option value="2">February</option>
  62. <option value="3">March</option>
  63. <option value="4">April</option>
  64. <option value="5">May</option>
  65. <option value="6">June</option>
  66. <option value="7">July</option>
  67. <option value="8">August</option>
  68. <option value="9">September</option>
  69. <option value="10">October</option>
  70. <option value="11">November</option>
  71. <option value="12">December</option>
  72. </select>
  73. Year
  74. <input type="text" name="year" size="4" value="">
  75. <input type="submit" value="Submit">
  76. </form>
  77. </body>
  78. </html>
Last edited by adatapost; Feb 9th, 2010 at 9:20 am. Reason: Added [code] tags. Encase your code in: [code] and [/code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JuliaNell is offline Offline
7 posts
since Feb 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: how to post the selected checkbox values
Next Thread in PHP Forum Timeline: Greeting Your Members & Guests





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC