![]() |
|
#1
|
|||
|
|||
|
is there any way to change it so it displays the month first, then day?
Also, can i make the month and day always be in double digits? like march would be 03 instead of 3? Thanks alot! Your script is amazing! -sheep |
|
#2
|
|||
|
|||
|
And for my database I need the yyyymmdd format (20070516).
Any idea how to change this in the javascript? BTW Great script! |
|
#3
|
|||
|
|||
|
Some changes in Calendar:
- dd/mm/yyyy (with comments) - yyyy-mm-dd (with comments) - dates with leading zero (03/01/2007 - 2007-01-03) - select date equal today-1 If you don't need today-1 can change the line: dip=((d-cd+1 < sd)&&(cm==sccm)&&(cy==sccy)); with: dip=((d-cd < sd)&&(cm==sccm)&&(cy==sccy)); Here the complete 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 document.write('<tr><td align=center style="background:#ABABAB;font:12px Arial">S</td><td align=center style="background:#ABABAB;font:12px Arial">M</td><td align=center style="background:#ABABAB;font:12px Arial">T</td><td align=center style="background:#ABABAB;font:12px Arial">W</td><td align=center style="background:#ABABAB;font:12px Arial">T</td><td align=center style="background:#ABABAB;font:12px Arial">F</td><td align=center style="background:#ABABAB;font:12px Arial">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.write('</div></div>'); document.all?document.attachEvent('onclick',checkC lick):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; pos = getPosition(ielem); getObj('fc').style.left = pos['x']+'px'; getObj('fc').style.top = (pos['y']+20)+'px'; 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='#FFCC66'; } function cs_out(e) { evtTgt(EvtObj(e)).style.background='#C4D3EA'; } 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','FEV','MAR','ABR','MAI','JUN','JUL','A GO','SET','OUT','NOV','DEZ'); 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='#C4D3EA'; obj.style.font='8px Lucida Grande,Lucida Sans Unicode,lucida,verdana,helvetica,sans-serif'; 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='#C4D3EA'; obj.style.font='8px Lucida Grande,Lucida Sans Unicode,lucida,verdana,helvetica,sans-serif'; 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 8px Lucida Grande,Lucida Sans Unicode,lucida,verdana,helvetica,sans-serif'; 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+1 < 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_o ut; getObj('v'+parseInt(d)).onclick=(dip)?null:cs_clic k; getObj('v'+parseInt(d)).innerHTML=d-cd; // MM-DD-YYYY with zeros - example: 03/01/2007 // calvalarr[d]=''+(d-cd)+'/'+(cm-(-1))+'/'+cy; // YYYY-MM-DD // calvalarr[d]=''+cy+"-"+leadingZero((cm-(-1)))+"-"+leadingZero((d-cd)); // DD/MM/YYYY calvalarr[d]=''+leadingZero((d-cd))+'/'+leadingZero((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; } } function getPosition(pObject) { var x = y = 0; if (pObject.offsetParent) { x = pObject.offsetLeft y = pObject.offsetTop while (pObject = pObject.offsetParent) { x += pObject.offsetLeft y += pObject.offsetTop } } tArray = new Array(); tArray['x'] = x; tArray['y'] = y;0 return tArray; } // leading zero - example: 01/03/2007 function leadingZero(nr) { if (nr < 10) nr = "0" + nr; return nr; } Last edited by souteimoso : 03-24-2007 at 01:43 PM. Reason: A better comment. |
|
#4
|
|||
|
|||
my editing and modifing scripts var beforedays = true; var beforemonth = true; var tekhane = false; /* true =4.8.2007 false= 04.08.2007*/ var date_format = 'my_day + "." + my_month + "." + my_year'; adding beforedays,beforemonth,date_format and double month and days |
|
#5
|
|||
|
|||
|
thanks for helping with the mm/dd/yyyy formating. i have it now when you click on the dates, they load in the proper format I need (mm/dd/yyyy), however once I choose a date, unclick off of the calendar and click back on, I get nothing in the calendar and the month displays "udefined".
My question is how do I make the calendar load the value of the input field now that it is in mm/dd/yyyy format? Thanks! |
|
#6
|
|||
|
|||
|
Topic was called... "Date format big, and also limit which dates are selectable?"
Link: http://boxover.swazz.org/forum/date-...le-t508-1.html |
|
#7
|
|||
|
|||
|
See my attached modification of the most recent release (retrieved 2007.07.24).
It's got some vars at the top to control the date format and if to prefix the dates and months with a '0' . The formatting is respected on the output value as well as the input parsing. I've also setup a variable to disable past date selections or to allow them. This is without adding much to the size (7.3KB). ...hope this helps someone... thanks, -alan- |
![]() |
| Thread Tools | |
| Display Modes | |
|
|