Simple and practical JavaScript Calendar control code

Source: Internet
Author: User
Tip: You can modify some of the code before running

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" > <ptml> <pead> <title>javascript Calendar builder generation Code-www.webdm.cn</title> </pead> <script language= "JavaScript" > <!--Begin function Fungetdaysinmonth (Themonth, theyear) {var theprevdate = new Date (theyear, themonth, 0); return theprevdate.getdate ();} function Funmakecalendar (theyear, themonth) {var mymonth = new Array (); mymonth[0] = new Array (7); mymonth[1] = new ARR Ay (7); MYMONTH[2] = new Array (7); MYMONTH[3] = new Array (7); MYMONTH[4] = new Array (7); MYMONTH[5] = new Array (7); MYMONTH[6] = new Array (7); var calendardate = new Date (theyear, theMonth-1, 1); var idayoffirst = Calendardate.getday (); var idaysinmonth = Fungetdaysinmonth (Themonth, theyear); var thedate = 1; var i, c, R; Mymonth[0][0] = "Sun"; MYMONTH[0][1] = "Mon"; MYMONTH[0][2] = "Tue"; MYMONTH[0][3] = "Wed"; MYMONTH[0][4] = "Thu"; MYMONTH[0][5] = "Fri"; MYMONTH[0][6] = "Sat"; for (c = Idayoffirst; c < 7; c++) {Mymonth[1][c] = thedate; thedate++; for (r = 2; r < 7; r++) {for (c = 0; c < 7; C + +) {if (thedate <= idaysinmonth) {mymonth[r ][C] = thedate; thedate++; }} return mymonth; function Fundrawcalendar (theyear, themonth) {var r,c; var mymonth; mymonth = Funmakecalendar (theyear, themonth); docum Ent.write ("<table border= ' 0 ' >") document.write ("<tr>"); document.write ("<td align= ' center ' >" + mymonth[0][0] + "</td>"); document.write ("<td align= ' center ' >" + mymonth[0][1] + "</td>"); document.write ("<td align= ' center ' >" + mymonth[0][2] + "</td>"); document.write ("<td align= ' center ' >" + mymonth[0][3] + "</td>"); document.write ("<td align= ' center ' >" + mymonth[0][4] + "</td>"); document.write ("<td align= ' center ' >" + mymonth[0][5] + "</td>"); document.write ("<td align= ' center ' >" + mymonth[0][6] + "</td>"); document.write ("&LT;/TR&Gt; "); for (r = 1; r < 7, r++) {document.write ("<tr>") for (c = 0; c < 7; C +) {rowid= "TD" +R+C; document.write ("<td id=" +rowid+ "Align=center valign=center width=30 height=30 >"); if (mymonth[r][c]>0) {document.write ("<font id=thedatetext >" + mymonth[r][c] + "</font>"); else {document.write ("<font id=thedatetext >" + " </font>"); } document.write ("</td>")} document.write ("</tr>"); } document.write ("</table>")} function Funupdatecalendar (Theyear, themonth) {var r,c; mymonth = Funmakecalendar (t Heyear, Themonth); for (r = 1; r < 7; r++) {for (c = 0; c < 7; C + +) {rowid= "TD" +R+C; if (mymonth[r][c]>0) {document.all[rowid].children[0].innertext=mymonth[r][c]; } else {document.all[rowid].children[0].innertext= ""; }}//End--> </script> <body leftmargin= "60px" > <form name= "FOrmcalendar "> <table border=" 1 "> <tr> <td> <select name=" Selectedmonth "onchange=" Funupdatecalendar (FormCalendar.SelectedYear.value, FormCalendar.SelectedMonth.value) ' > <option value= "1" >January</option> <option value= "2" >February</option> <option value= "3" >march</ Option> <option value= "4" >April</option> <option value= "5" >May</option> <option value= "6" >June</option> <option value= "7" >July</option> <option value= "8" >august</option > <option value= "9" >September    </option> <option value= "Ten" >October< /option> <option value= "One" >November</option> <option value= "a" >December</option> </ select>   <select name= "selectedyear" Onchange= ' Funupdatecalendar (FormCalendar.SelectedYear.value, FormCalendar.SelectedMonth.value) ' > <option value= ' 1995 ' >1995         </option> <option value= "1996" >1996</option> <option value= "1997" >1997 </option> <option value= "1998" >1998</option> <option value= "1999" >1999</option> < Option value= "<option" >2000</option> value= "2001" >2001</option> <option value= "2002" >2002</option> <option value= "2003" >2003</option> <option value= ">2004</option" > <option value= "<option" >2005</option> value= "2006" >2006</option> <option value= "2007" >2007</option> <option value= "2008" >2008</option> </select> </td> </tr > <tr> <script language= "JavaScript" > <!--Begin var currentdate = new Date (); Formcalendar.selectedmonth.options[currentdate.getmonth ()].selected = true; if (Currentdate.getyear () <2000) currentyear= "+currentdate.getyear" (); else Currentyear=currentdate.getyear (); for (i = 0; i < FORMCALENDAR.SElectedyear.length; i++) {if (Formcalendar.selectedyear.options[i].value ==currentyear) formcalendar.selectedyear.options[i].selected = True }//end--> </script> <td> <script language= "JavaScript" > var currentdate = new Date (); Fundrawcalendar (Currentdate.getfullyear (), Currentdate.getmonth () +1); </script> </td> </tr> </table> </form> </body> </ptml> <br/> </td > </tr> </table>
Tip: You can modify some of the code before running
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.