Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 26th, 2005, 04:31 PM
shamrog12's Avatar
shamrog12 shamrog12 is offline
Newton's Apple Wizard
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 1,661 shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Weeks 2 Days 2 h 39 m 22 sec
Reputation Power: 34
Send a message via AIM to shamrog12
javascript date selector

javascript Code:
Original - javascript Code
  1. <head>
  2.  
  3. <script type="text/javascript">
  4.  
  5. <!-- Begin
  6. //set todays date
  7. Now = new Date();
  8. NowDay = Now.getDate();
  9. NowMonth = Now.getMonth();
  10. NowYear = Now.getYear();
  11. if (NowYear < 2000) NowYear += 1900; //for Netscape
  12.  
  13. //function for returning how many days there are in a month including leap years
  14. function DaysInMonth(WhichMonth, WhichYear)
  15. {
  16.   var DaysInMonth = 31;
  17.   if (WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30;
  18.   if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(WhichYear/4))  DaysInMonth = 28;
  19.   if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(WhichYear/4))  DaysInMonth = 29;
  20.   return DaysInMonth;
  21. }
  22.  
  23. //function to change the available days in a months
  24. function ChangeOptionDays(Which)
  25. {
  26.   DaysObject = eval("document.Form1." + Which + "Day");
  27.   MonthObject = eval("document.Form1." + Which + "Month");
  28.   YearObject = eval("document.Form1." + Which + "Year");
  29.  
  30.   Month = MonthObject[MonthObject.selectedIndex].text;
  31.   Year = YearObject[YearObject.selectedIndex].text;
  32.  
  33.   DaysForThisSelection = DaysInMonth(Month, Year);
  34.   CurrentDaysInSelection = DaysObject.length;
  35.   if (CurrentDaysInSelection > DaysForThisSelection)
  36.   {
  37.     for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)
  38.     {
  39.       DaysObject.options[DaysObject.options.length - 1] = null
  40.     }
  41.   }
  42.   if (DaysForThisSelection > CurrentDaysInSelection)
  43.   {
  44.     for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)
  45.     {
  46.       NewOption = new Option(DaysObject.options.length + 1);
  47.       DaysObject.add(NewOption);
  48.     }
  49.   }
  50.     if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
  51. }
  52.  
  53. //function to set options to today
  54. function SetToToday(Which)
  55. {
  56.   DaysObject = eval("document.Form1." + Which + "Day");
  57.   MonthObject = eval("document.Form1." + Which + "Month");
  58.   YearObject = eval("document.Form1." + Which + "Year");
  59.  
  60.   YearObject[0].selected = true;
  61.   MonthObject[NowMonth].selected = true;
  62.  
  63.   ChangeOptionDays(Which);
  64.  
  65.   DaysObject[NowDay-1].selected = true;
  66. }
  67.  
  68. //function to write option years plus x
  69. function WriteYearOptions(YearsAhead)
  70. {
  71.   line = "";
  72.   for (i=0; i<YearsAhead; i++)
  73.   {
  74.     line += "<OPTION>";
  75.     line += NowYear + i;
  76.   }
  77.   return line;
  78. }
  79. //  End -->
  80. </script>
  81.  
  82. </head>
  83.  
  84. <body onLoad="SetToToday('FirstSelect');">
  85.  
  86. <FORM name="Form1">
  87. <SELECT name="FirstSelectDay">
  88.     <OPTION>1
  89.     <OPTION>2
  90.     <OPTION>3
  91.     <OPTION>4
  92.     <OPTION>5
  93.     <OPTION>6
  94.     <OPTION>7
  95.     <OPTION>8
  96.     <OPTION>9
  97.     <OPTION>10
  98.     <OPTION>11
  99.     <OPTION>12
  100.     <OPTION>13
  101.     <OPTION>14
  102.     <OPTION>15
  103.     <OPTION>16
  104.     <OPTION>17
  105.     <OPTION>18
  106.     <OPTION>19
  107.     <OPTION>20
  108.     <OPTION>21
  109.     <OPTION>22
  110.     <OPTION>23
  111.     <OPTION>24
  112.     <OPTION>25
  113.     <OPTION>26
  114.     <OPTION>27
  115.     <OPTION>28
  116.     <OPTION>29
  117.     <OPTION>30
  118.     <OPTION>31
  119. </SELECT>
  120. <SELECT name="FirstSelectMonth" onchange="ChangeOptionDays('FirstSelect')">
  121.     <OPTION>Jan
  122.     <OPTION>Feb
  123.     <OPTION>Mar
  124.     <OPTION>Apr
  125.     <OPTION>May
  126.     <OPTION>Jun
  127.     <OPTION>Jul
  128.     <OPTION>Aug
  129.     <OPTION>Sep
  130.     <OPTION>Oct
  131.     <OPTION>Nov
  132.     <OPTION>Dec
  133. </SELECT>
  134. <SELECT name="FirstSelectYear" onchange="ChangeOptionDays('FirstSelect')">
  135.     <SCRIPT language="JavaScript">
  136.         document.write(WriteYearOptions(50));
  137.     </SCRIPT>
  138. </SELECT>
  139. </form>
  140.  
  141. <p><center>
  142. <font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
  143. by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
  144. </center><p>
Comments on this post
Shadow Wizard agrees: well deserved points.... keep it flowing!
sinner8347 agrees!
__________________
If you found a post of mine helpful, please click on the on my post to add to my reputation.


Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > javascript date selector


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway