JavaScript - Date Script - X Ammount Of Days
Hello everyone,
I have a date script, but I want it to be adjusted so for example today it's September 17th 2009, but I want it to say September 15th 2009, so it removes automaticly 2 days.. I tried allot of things but I am not a javascript expert, I hope someone can help me out! Code: <script language="JavaScript" type="text/javascript"> <!-- var month = new Array(); month[0]="January"; month[1]="February"; month[2]="March"; month[3]="April"; month[4]="May"; month[5]="June"; month[6]="July"; month[7]="August"; month[8]="September"; month[9]="October"; month[10]="November"; month[11]="December"; var day = new Array(); day[0]="Sunday"; day[1]="Monday"; day[2]="Tuesday"; day[3]="Wednesday"; day[4]="Thursday"; day[5]="Friday"; day[6]="Saturday"; today = new Date(); date = today.getDate(); day = (day[today.getDay()]); month = (month[today.getMonth()]); year = (today.getFullYear()); suffix = (date==1 || date==21 || date==31) ? "st" : "th" && (date==2 || date==22) ? "nd" : "th" && (date==3 || date==23) ? "rd" : "th" function print_date() { document.write(day + "," + " " + date + "<sup>" + suffix + "</sup>" + " " + month + "," + " " + year); } // --> </script> <script> <!-- print_date(); //--> </script> Similar TutorialsNot sure if this is possible in javascript: I'm looking for two different dates (bill date and due date) on an invoice that are captured by OCR. If one of them exists, but the other does not, I want the empty field to be 14 days before (or after) the other. For example: if the bill date is 7/27/2010 and the due date was not captured, I want to set the due date as 8/10/2010 (14 days after the bill date). If the due date was captured as 8/10/2010, but the due date is blank, I want to assign the bill date as 7/27/2010 (14 days before the due date). if both dates have values, do nothing. Thanks. Hi, I need to add days to a date in javascript, My requirement is as follows: Date is coming from a textbox. eg:- 26/07/2010 days from this statement var day1=document.getElementById('<%=HiddenDate.ClientID %>').value; an eg:- if the date is 28/01/2012 and days Needed to be added=5 the added date should be 02/02/2012. Can anybody help me? Thanks Jamuna Hello, I have a textbox with a date formatted 'dd/mm/yyyy'. I want to be able to add days to the date so that the month ticks over if the days exceed the days in the month and the year also if the month value passes 12. Currently I have the below. This adds to the days but will not tick over the month. Any help please. Thanks Code: <html> <head> <script type="text/javascript"> function calDate() { var dateArr = document.getElementById('testinput').value; var myDate = new Date(); var day; var month; var year; day = dateArr.substring(0,2); month = dateArr.substring(3,5); year = dateArr.substring(6,10); if (day.charAt(0) == '0') { day = day.charAt(1); } if (month.charAt(0) == '0') { month = month.charAt(1); } myDate.setDate(day); myDate.setMonth(month); // January = 0 myDate.setFullYear(year); alert((myDate.getDate()+28)+ "/" + (myDate.getMonth()) + "/" + myDate.getFullYear()); } </script> </head> <body> <a href="javascript:void(0);" onclick="calDate();"> click</a><input type="text" id="days" value="0"/> </body> </html> I'm just trying to add X days to a given date object. However, it's not the right answer (did it in PHP to check, and my PHP version works). dateObj = new Date (month + '/' + day + '/' + year); // Grab the object for a given date datestamp = dateObj.getTime(); // Get millisecond timestamp newDate = new Date (datestamp + (1000 * 60 * 60 * 24 * parseInt (daysToAdd))); // Add "daysToAdd" days to the date alert (newDate); It's not daysToAdd days away... Any help is greatly appreciated. I wrote a version not using the Date () object, but rather an array of the days in each month, and then subtracting each month until "day" was below 31, etc. It's a lot less efficient than this method though :P I am trying to figure out how to calculate the date 30 days ago. I also will need to be able to change the interval. Anyone have a piece of code that does this? Hi Guys, Is it possible to add a certain number of days (determined by a select box option) to a date in the format of Thursday, 26 January, 2012 ?? Thanks Please help I am a newbie and need some assistant. I'm trying to get a full date. In this script I want the user to be able to enter a date and get a 1000 day result a full (date) mm/dd/yyy. So far this give me the year only. I've tried so many ways. <script language="javascript"> var reply = prompt("Please enter the date you and your love begin dating (mm/dd/yyyy)", " "); var newstring = new String(reply); var arrTemp = new Array(); arrTemp = newstring.split("/"); var year = parseInt(arrTemp[arrTemp.length-1]); year += 3; alert("You begin dating your love in " + parseInt(arrTemp[arrTemp.length-1]) + "\nYou should be married before or in the year of " + year); </script> I've written a js function to find the difference between two dates. the format being used is dd/mm/yyyy hh:mm. The function returns correct value when give one set of values, but go wrong with another set. examples are given below. set 1 : Time 1 = 24/02/2011 09:30 , time 2 = 24/02/2011 16:00 Output is corret here. It gives 6 Hours & 30 Minutes (after converting the difference) set 2: Time 1 = 24/02/2011 09:30 , time 2 = 25/02/2011 16:00 Here, it gives 31 days, 6 Hours & 30 Minutes. My code is given below. Also the alert of dates display strange values. Don't know if it is timezone issue. I wonder what is going wrong here Code: function compareDateTime(frmtime,totime) { var date1 = new Date(frmtime); var date2 = new Date(totime); var diff = new Date(); alert(date1); alert(date2); diff = (date2.getTime()-date1.getTime()); if (diff<0) { alert("From Time cannot be later than To Time!"); return 0; } else if (diff==0) { alert("From Time cannot be equal with To Time!"); return 0; } else { return diff; } } The returned diff value is broken down as following: Code: if (diff>0) { days = Math.floor(diff / (1000 * 60 * 60 * 24)); diff -= days * (1000 * 60 * 60 * 24); hours = Math.floor(diff / (1000 * 60 * 60)); diff -= hours * (1000 * 60 * 60); mins = Math.floor(diff / (1000 * 60)); alert(days+","+hours+","+mins); return true; } what am i doing wrong here? hello there this is in vb script. but i dont where to post it. can any one hlep me out plzz I need to check if the date entered by user is within 5th date from current date. I am trying to do it this way entered date has month and date value Code: sResvDate = 01/24 Set sMaxDays to getdate(5) but get date will give year too. and how do i compare if it less than 5th day or not. I have the following code on my site. I use this in the header of mysite Code: <script type="text/javascript"> var weekdaystxt=["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"] var montharray=("January","February","March","April","May","June","July","August","September","October","November","December") function showLocalgetthedate(){ var mydate=new Date() var year=mydate.getYear() if (year < 1000) year+=1900 var day=mydate.getDay() var month=mydate.getMonth() var daym=mydate.getDate() if (daym<10) daym="0"+daym function showLocalTime(container, servermode, offsetMinutes, displayversion){ if (!document.getElementById || !document.getElementById(container)) return this.container=document.getElementById(container) this.displayversion=displayversion var servertimestring=(servermode=="server-php")? '<? print date("F d, Y H:i:s", time())?>' : (servermode=="server-ssi")? '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' : '<%= Now() %>' this.localtime=this.serverdate=new Date(servertimestring) this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000) //add user offset to server time this.updateTime() this.updateContainer() } showLocalTime.prototype.updateTime=function(){ var thisobj=this this.localtime.setSeconds(this.localtime.getSeconds()+1) setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second } showLocalTime.prototype.updateContainer=function(){ var thisobj=this if (this.displayversion=="long") this.container.innerHTML=this.localtime.toLocaleString() else{ var hour=this.localtime.getHours() var minutes=this.localtime.getMinutes() var seconds=this.localtime.getSeconds() var ampm=(hour>=12)? "PM" : "AM" var dayofweek=weekdaystxt[this.localtime.getDay()] this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+ " "+montharray(month)+" ("+dayofweek+")" } setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second } function formatField(num, isHour){ </script> I use this to display the information. Code: <script type="text/javascript"> new showLocalTime("timecontainer", "server-php", 0, "short") new showLocalTime("timecontainer2", "server-php", +300, "short") new showLocalTime("timecontainer3", "server-php", +360, "short") new showLocalTime("timecontainer4", "server-php", +600, "short") </script> This gives me 4 clocks which i set at different time zones Can someone assist me in showing me a way to accelerate the time for this clock. I would like the minutes to be only 5 seconds long versus the normal 60 seconds per minute. I fly a flight sim and the in game world clock is accelerated at this pace and my squad would like to be able to see the time it would currently be in the game so we can avoid launching the game at certain in game times. If this can't be done, does anyone know of a separate java script that can accomplish this? Thank you in advance, any and all help would be greatly appreciated. Could someone edit this script so the date is always 2 weeks infront of the actual date? <script language="JavaScript"> <!-- var now = new Date(); var days = new Array( 'Sunday','Monday','Tuesday', 'Wednesday','Thursday','Friday','Saturday'); var months = new Array( 'January','February','March','April','May', 'June','July','August','September','October', 'November','December'); var date = ((now.getDate()<10) ? "0" : "")+ now.getDate(); function fourdigits(number) { return (number < 1000) ? number + 1900 : number;} today = days[now.getDay()] + ", " + months[now.getMonth()] + " " + date + ", " + (fourdigits(now.getYear())); document.write(today); //--> </script> Thanks Quote: <SCRIPT LANGUAGE="JavaScript1.2"> <!-- Begin var days=new Array(8); days[1]="Monday"; days[2]="Tuesday"; days[3]="Wednesday"; days[4]="Thursday"; days[5]="Friday"; days[6]="Saturday"; days[7]="Sunday"; var months=new Array(13); months[1]="January"; months[2]="February"; months[3]="March"; months[4]="April"; months[5]="May"; months[6]="June"; months[7]="July"; months[8]="August"; months[9]="September"; months[10]="October"; months[11]="November"; months[12]="December"; var time=new Date(); var lmonth=months[time.getMonth() + 1]; var ldays=days[time.getDay() + 1]; var date=time.getDate(); var year=time.getYear(); var hour=time.getHours(); var min=time.getMinutes() if (year < 2000) year = year + 1900; if (hour > 15) { date = date + 1; } document.write("<center>" + lmonth +" "); document.write(date + ", " + year + "</center>"); // End --> </SCRIPT> </CENTER> Can anyone help me edit this so that on Saturday at 10am the date displays mondays date. Thanks What I am looking to do is auto-populate a number of forms based on what a user chooses as a starting date. For example: If a user enters 12/12/2009 I want the other fields to automatically populate with the next 2 weeks (12/13/2009, 12/14/2009, 12/15/2009 etc.) Anyone have a useful script that I can use given that these fields are formatted as dates? The idea is to save time by only having to fill in the first date in the timesheet. HI all, maybe someone can help me. I am using this script: http://www.javascriptkit.com/script/...selector.shtml on my site but as of Feb 1st 2012 the day of the week and the date do not match anymore. Feb 1st 2012 is not a thursday. Try example on site (link) to see what I mean. Can anyone help me debug this? Any help greatly appreciated Dennis I have been using the following script for some time and it has only just been made known to me that it fails on todays date ! not sure if this is the case for other days but the days of the week are all messed up and do not show correctly for a date in June 2011. Code: var ds_i_date = new Date(); ds_c_month = ds_i_date.getMonth() + 1; ds_c_year = ds_i_date.getFullYear(); // Get Element By Id function ds_getel(id) { return document.getElementById(id); } // Get the left and the top of the element. function ds_getleft(el) { var tmp = el.offsetLeft; el = el.offsetParent while(el) { tmp += el.offsetLeft; el = el.offsetParent; } return tmp; } function ds_gettop(el) { var tmp = el.offsetTop; el = el.offsetParent while(el) { tmp += el.offsetTop; el = el.offsetParent; } return tmp; } // Output Element var ds_oe = ds_getel('ds_calclass'); // Container var ds_ce = ds_getel('ds_conclass'); // Output Buffering var ds_ob = ''; function ds_ob_clean() { ds_ob = ''; } function ds_ob_flush() { ds_oe.innerHTML = ds_ob; ds_ob_clean(); } function ds_echo(t) { ds_ob += t; } var ds_element; // Text Element... var ds_monthnames = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; // You can translate it for your language. var ds_daynames = [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ]; // You can translate it for your language. // Calendar template function ds_template_main_above(t) { return '<table cellpadding="3" cellspacing="1" class="ds_tbl">' + '<tr>' + '<td class="ds_head" style="cursor: pointer" onclick="ds_py();"><<</td>' + '<td class="ds_head" style="cursor: pointer" onclick="ds_pm();"><</td>' + '<td class="ds_head" style="cursor: pointer" onclick="ds_hi();" colspan="3">[Close]</td>' + '<td class="ds_head" style="cursor: pointer" onclick="ds_nm();">></td>' + '<td class="ds_head" style="cursor: pointer" onclick="ds_ny();">>></td>' + '</tr>' + '<tr>' + '<td colspan="7" class="ds_head">' + t + '</td>' + '</tr>' + '<tr>'; } function ds_template_day_row(t) { return '<td class="ds_subhead">' + t + '</td>'; // Define width in CSS, XHTML 1.0 Strict doesn't have width property for it. } function ds_template_new_week() { return '</tr><tr>'; } function ds_template_blank_cell(colspan) { return '<td colspan="' + colspan + '"></td>' } function ds_template_day(d, m, y) { return '<td class="ds_cell" onMouseout="this.style.background=\'#EEE\';" onMouseover="this.style.background=\'#999\';" onclick="ds_onclick(' + d + ',' + m + ',' + y + ')">' + d + '</td>'; // Define width the day row. } function ds_template_main_below() { return '</tr>' + '</table>'; } // This one draws calendar... function ds_draw_calendar(m, y) { // First clean the output buffer. ds_ob_clean(); // Here we go, do the header ds_echo (ds_template_main_above(ds_monthnames[m - 1] + ' ' + y)); for (i = 0; i < 7; i ++) { ds_echo (ds_template_day_row(ds_daynames[i])); } // Make a date object. var ds_dc_date = new Date(); ds_dc_date.setMonth(m - 1); ds_dc_date.setFullYear(y); ds_dc_date.setDate(1); if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) { days = 31; } else if (m == 4 || m == 6 || m == 9 || m == 11) { days = 30; } else { days = (y % 4 == 0) ? 29 : 28; } var first_day = ds_dc_date.getDay(); var first_loop = 1; // Start the first week ds_echo (ds_template_new_week()); // If sunday is not the first day of the month, make a blank cell... if (first_day != 0) { ds_echo (ds_template_blank_cell(first_day)); } var j = first_day; for (i = 0; i < days; i ++) { // Today is sunday, make a new week. // If this sunday is the first day of the month, // we've made a new row for you already. if (j == 0 && !first_loop) { // New week!! ds_echo (ds_template_new_week()); } // Make a row of that day! ds_echo (ds_template_day(i + 1, m, y)); // This is not first loop anymore... first_loop = 0; // What is the next day? j ++; j %= 7; } // Do the footer ds_echo (ds_template_main_below()); // And let's display.. ds_ob_flush(); // Scroll it into view. //ds_ce.scrollIntoView(); } // A function to show the calendar. // When user click on the date, it will set the content of t. function ds_sh(t) { // Set the element to set... ds_element = t; // Make a new date, and set the current month and year. var ds_sh_date = new Date(); ds_c_month = ds_sh_date.getMonth() + 1; ds_c_year = ds_sh_date.getFullYear(); // Draw the calendar ds_draw_calendar(ds_c_month, ds_c_year); // To change the position properly, we must show it first. ds_ce.style.display = ''; // Move the calendar container! the_left = ds_getleft(t); the_top = ds_gettop(t) + t.offsetHeight; ds_ce.style.left = the_left + 'px'; ds_ce.style.top = the_top + 'px'; // Scroll it into view. //ds_ce.scrollIntoView(); } // Hide the calendar. function ds_hi() { ds_ce.style.display = 'none'; } // Moves to the next month... function ds_nm() { // Increase the current month. ds_c_month ++; // We have passed December, let's go to the next year. // Increase the current year, and set the current month to January. if (ds_c_month > 12) { ds_c_month = 1; ds_c_year++; } // Redraw the calendar. ds_draw_calendar(ds_c_month, ds_c_year); } // Moves to the previous month... function ds_pm() { ds_c_month = ds_c_month - 1; // Can't use dash-dash here, it will make the page invalid. // We have passed January, let's go back to the previous year. // Decrease the current year, and set the current month to December. if (ds_c_month < 1) { ds_c_month = 12; ds_c_year = ds_c_year - 1; // Can't use dash-dash here, it will make the page invalid. } // Redraw the calendar. ds_draw_calendar(ds_c_month, ds_c_year); } // Moves to the next year... function ds_ny() { // Increase the current year. ds_c_year++; // Redraw the calendar. ds_draw_calendar(ds_c_month, ds_c_year); } // Moves to the previous year... function ds_py() { // Decrease the current year. ds_c_year = ds_c_year - 1; // Can't use dash-dash here, it will make the page invalid. // Redraw the calendar. ds_draw_calendar(ds_c_month, ds_c_year); } // Format the date to output. function ds_format_date(d, m, y) { // 2 digits month. m2 = '00' + m; m2 = m2.substr(m2.length - 2); // 2 digits day. d2 = '00' + d; d2 = d2.substr(d2.length - 2); // YYYY-MM-DD return d2 + '-' + m2 + '-' + y; } // When the user clicks the day. function ds_onclick(d, m, y) { // Hide the calendar. ds_hi(); // Set the value of it, if we can. if (typeof(ds_element.value) != 'undefined') { ds_element.value = ds_format_date(d, m, y); // this part is a personal bit of code to allow my page to update correctly and in time. if("fireEvent" in ds_element) ds_element.fireEvent("onChange"); else { var evt = document.createEvent("HTMLEvents"); evt.initEvent("change", false, true); ds_element.dispatchEvent(evt); } // // Maybe we want to set the HTML in it. } else if (typeof(ds_element.innerHTML) != 'undefined') { ds_element.innerHTML = ds_format_date(d, m, y); // I don't know how should we display it, just alert it to user. } else { alert (ds_format_date(d, m, y)); } } Hi Script Experts I am facing issue in below code for Brisilia time zone.(GMT-3). Issue comes in October month only. It is going tobig loop. I am not getting how Date object is behaving here. Thanks in advance Pranav Sharma *********************************** <script type="text/javascript"> var nDate; var nCurrentYear = 2011; var nCurrentMonth = 10; nYear=2011; nMonth=10; var date = new Date(nYear, nMonth-1, 1); document.write('Month:'+date.getMonth() +':CurrentMonth:'+nCurrentMonth); while (date.getMonth() == nCurrentMonth-1) { nDate = date.getDate(); document.write(date.toDateString()); date = new Date(nCurrentYear, date.getMonth(), date.getDate()+1); } </script> ********************************** I am attempting to create a javascript code that will write out the lyrics to the popular Christmas song, The 12 Days of Christmas. Here is what I have so far; Code: <?xml version = "1.0" encoding = "utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns = "http://www.w3.org/1999/xhtml"> <head> <title>ITS 200 Project 5: 12 Days of Christmas</title> <script type = "text/javascript"> <!-- document.writeln ("<h1> The 12 Days of Christmas </h1>"); for (var i =1; i = 12; i++) { var day; var addline; var gift; var pastline; switch(i) { case 1: day = "first"; addline = "A partridge in a pear tree."; pastline = "and" + addline; break; case 2: day = "second"; addline = "Two Turtle Doves"; break; case 3: day = "third"; addline = "Three French Hens"; break; case 4: day = "fourth"; addline = "Four Calling Birds"; break; case 5: day = "fifth"; addline = "FIIIIVEEE GOOOOLDEN RIIIINGS!!!!!!"; break; case 6: day = "sixth"; addline = "Six Geese-a-laying"; break; case 7: day = "seventh"; addline = "Seven Swans-a-swimming"; break; case 8: day = "eighth"; addline = "Eight Maids-a-milking"; break; case 9: day = "ninth"; addline = "Nine Ladies Dancing"; break; case 10: day = "tenth"; addline = "Ten Lords-a-leaping"; break; case 11: day = "eleventh"; addline = "Eleven Pipers Piping"; break; case 12: day = "twelfth"; addline = "Twelve Drummers Drumming"; break; } // end switch if (i==1) gift = addline; else { gift = addline + "<br>" + pastline; pastline = gift; } // end else document.writeln("<br>On the" + day + "of Christmas<br> my true love sent to me:"<br> + gift); } //--> </script> </head> <body> </body> </html> I have no idea why only the heading is coming up!? I have 2 dates in variables (formatted like 'Wed Jan 18 2012 01:01:01 GMT+0000 (BST)') I need to minus them to get the days This worked if they were in the same month var amountOfDays = date.getDate() - datefirst.getDate(); However if the dates where in 2 different months it doesnt work. How would i do it better 2 months? Hi, I am using the jQuery UI Datepicker - Event Search. as a booking-system. I want to automatically disable days from my MYSQL table in my booking-system (datePicker). So, here is the deal: In my website, there is booking-system, you can reserve a room from datePicker. I have successfully created a PHP, which sends the information (name, room, date etc.) to my MYSQL. Then I have successfully created a datesonly.php, which prints only a dates from my MYSQL. So now I have to make javascript (?) which reads dates from datesonly.php and draws a booked-note to my datePicker at website (so people can see which days are booked --> no double-books!). Booked-note should be something like that day in datePicker is red. Thank you! And sorry for my bad english, I'm from Finland. EDIT: Sorry, the title should be: Disabling days from datePicker via JavaScript Hello, I need to disable the first 3 days of a popup calendar so that users can only select a date which is 3 days in advance to the present date. I dont really know javascript so i would really appreciate if someone can help me out in this. Calendar code can be found below. Code: /* --- Swazz Javascript Calendar --- /* --- v 1.0 3rd November 2006 By Oliver Bryant http://calendar.swazz.org */ function getObj(objID) { if (document.getElementById) {return document.getElementById(objID);} else if (document.all) {return document.all[objID];} else if (document.layers) {return document.layers[objID];} } function checkClick(e) { e?evt=e:evt=event; CSE=evt.target?evt.target:evt.srcElement; if (getObj('fc')) if (!isChild(CSE,getObj('fc'))) getObj('fc').style.display='none'; } function isChild(s,d) { while(s) { if (s==d) return true; s=s.parentNode; } return false; } function Left(obj) { var curleft = 0; if (obj.offsetParent) { while (obj.offsetParent) { curleft += obj.offsetLeft obj = obj.offsetParent; } } else if (obj.x) curleft += obj.x; return curleft; } function Top(obj) { var curtop = 0; if (obj.offsetParent) { while (obj.offsetParent) { curtop += obj.offsetTop obj = obj.offsetParent; } } else if (obj.y) curtop += obj.y; return curtop; } document.write('<table id="fc" style="position:absolute;border-collapse:collapse;background:#FFFFFF;border:1px solid #ABABAB;display:none" cellpadding=2>'); document.write('<tr><td style="cursor:pointer" onclick="csubm()"><img src="../../public/front/includes/classes/images/arrowleftmonth.gif"></td><td colspan=5 id="mns" align="center" style="font:bold 13px Verdana"></td><td align="right" style="cursor:pointer" onclick="caddm()"><img src="../../public/front/includes/classes/images/arrowrightmonth.gif"></td></tr>'); document.write('<tr><td align=center style="background:#ABABAB;font:12px Verdana">S</td><td align=center style="background:#ABABAB;font:12px Verdana">M</td><td align=center style="background:#ABABAB;font:12px Verdana">T</td><td align=center style="background:#ABABAB;font:12px Verdana">W</td><td align=center style="background:#ABABAB;font:12px Verdana">T</td><td align=center style="background:#ABABAB;font:12px Verdana">F</td><td align=center style="background:#ABABAB;font:12px Verdana">S</td></tr>'); for(var kk=1;kk<=6;kk++) { document.write('<tr>'); for(var tt=1;tt<=7;tt++) { num=7 * (kk-1) - (-tt); document.write('<td id="v' + num + '" style="width:18px;height:18px"> </td>'); } document.write('</tr>'); } document.write('</table>'); document.all?document.attachEvent('onclick',checkClick):document.addEventListener('click',checkClick,false); // Calendar script var now = new Date; var sccm=now.getMonth(); var sccy=now.getFullYear(); var ccm=now.getMonth(); var ccy=now.getFullYear(); var updobj; function lcs(ielem) { updobj=ielem; getObj('fc').style.left=Left(ielem); getObj('fc').style.top=Top(ielem)+ielem.offsetHeight; getObj('fc').style.display=''; // First check date is valid curdt=ielem.value; curdtarr=curdt.split('/'); isdt=true; for(var k=0;k<curdtarr.length;k++) { if (isNaN(curdtarr[k])) isdt=false; } if (isdt&(curdtarr.length==3)) { ccm=curdtarr[1]-1; ccy=curdtarr[2]; prepcalendar(curdtarr[0],curdtarr[1]-1,curdtarr[2]); } } function evtTgt(e) { var el; if(e.target)el=e.target; else if(e.srcElement)el=e.srcElement; if(el.nodeType==3)el=el.parentNode; // defeat Safari bug return el; } function EvtObj(e){if(!e)e=window.event;return e;} function cs_over(e) { evtTgt(EvtObj(e)).style.background='#CD2F30'; } function cs_out(e) { evtTgt(EvtObj(e)).style.background='#F0F0F0'; } function cs_click(e) { updobj.value=calvalarr[evtTgt(EvtObj(e)).id.substring(1,evtTgt(EvtObj(e)).id.length)]; getObj('fc').style.display='none'; } var mn=new Array('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'); var mnn=new Array('31','28','31','30','31','30','31','31','30','31','30','31'); var mnl=new Array('31','29','31','30','31','30','31','31','30','31','30','31'); var calvalarr=new Array(42); function f_cps(obj) { obj.style.background='#F0F0F0'; obj.style.font='10px Verdana'; obj.style.color='#333333'; obj.style.textAlign='center'; obj.style.textDecoration='none'; obj.style.border='1px solid #6487AE'; obj.style.cursor='pointer'; } function f_cpps(obj) { obj.style.background='#F0F0F0'; obj.style.font='10px Verdana'; obj.style.color='#ABABAB'; obj.style.textAlign='center'; obj.style.textDecoration='line-through'; obj.style.border='1px solid #6487AE'; obj.style.cursor='default'; } function f_hds(obj) { obj.style.background='#FFF799'; obj.style.font='bold 10px Verdana'; obj.style.color='#333333'; obj.style.textAlign='center'; obj.style.border='1px solid #6487AE'; obj.style.cursor='pointer'; } // day selected function prepcalendar(hd,cm,cy) { now=new Date(); sd=now.getDate(); td=new Date(); td.setDate(1); td.setFullYear(cy); td.setMonth(cm); cd=td.getDay(); getObj('mns').innerHTML=mn[cm]+ ' ' + cy; marr=((cy%4)==0)?mnl:mnn; for(var d=1;d<=42;d++) { f_cps(getObj('v'+parseInt(d))); if ((d >= (cd -(-1))) && (d<=cd-(-marr[cm]))) { dip=((d-cd < sd)&&(cm==sccm)&&(cy==sccy)); htd=((hd!='')&&(d-cd==hd)); if (dip) f_cpps(getObj('v'+parseInt(d))); else if (htd) f_hds(getObj('v'+parseInt(d))); else f_cps(getObj('v'+parseInt(d))); getObj('v'+parseInt(d)).onmouseover=(dip)?null:cs_over; getObj('v'+parseInt(d)).onmouseout=(dip)?null:cs_out; getObj('v'+parseInt(d)).onclick=(dip)?null:cs_click; getObj('v'+parseInt(d)).innerHTML=d-cd; calvalarr[d]=''+(d-cd)+'-'+(cm-(-1))+'-'+cy; } else { getObj('v'+d).innerHTML=' '; getObj('v'+parseInt(d)).onmouseover=null; getObj('v'+parseInt(d)).onmouseout=null; getObj('v'+parseInt(d)).style.cursor='default'; } } } prepcalendar('',ccm,ccy); //getObj('fc'+cc).style.visibility='hidden'; function caddm() { marr=((ccy%4)==0)?mnl:mnn; ccm+=1; if (ccm>=12) { ccm=0; ccy++; } cdayf(); prepcalendar('',ccm,ccy); } function csubm() { marr=((ccy%4)==0)?mnl:mnn; ccm-=1; if (ccm<0) { ccm=11; ccy--; } cdayf(); prepcalendar('',ccm,ccy); } function cdayf() { if ((ccy>sccy)|((ccy==sccy)&&(ccm>=sccm))) return; else { ccy=sccy; ccm=sccm; cfd=scfd; } } Thank you very much in advance Sami |