Home


javascript calendar widget

This is a calendar to be used as a date picker, or date display. Can be used in as many instances as you want, with some handy options.
THIS VERSION IS NOW DEPRECATED. THE NEW VERSION CAN BE FOUND HERE
Download Download

OVERVIEW:

There are 2 modes for the calendar: Strict and Loose. In strict mode, the calendar has the date selection limited, to a certain period defined in days(see flags & options for details). In loose mode, the calendar has the date selection unlimited.

You can choose the returned date format, as well as how the date should be filled back:full date in one input, or multiple inputs(see flags&options for details).

The look of the calendar is fully CSS customizable. You’ll find the css file in the .zip along with the js file (you’ll have to include both in your template) .

I’ve tried to make the calendar to serve as a stand alone script, but it can be easily be integrated in other projects, and you can even take the calendar’s development further if you need for a more specific job for it.

DEMO

choose


FLAGS & OPTIONS

NOTE: all flags&options are optional. They all degrade to default values as specified bellow.

iMonth

Values: 0-11
if not set it will default to user’s PC month date.

iYear

Values: >2000
if not set it will default to the user’s PC year date.

iDay

Values: 0-31
if not set it will default to the user’s PC day date.

itype

Values: “strict” or “loose”
if not set it will default to “loose”.

imaxDays

values: >0

Only counts if itype=”strict”. If set, it will enable the date selection for a range specified in days starting from iDay/iMonth/iYear. For example it will enable selection from today 300 days forward.

addZero

values: true or false

Convert single character days & months to 2 characters by adding a 0 in front (Eg. 9 becomes 09)

folowMouse

values: true or false
Display the calendar at the mouse position + offX/offY (see bellow) . Defaults to “true”. Also in the css file the #calendar should have the position attribute “position: absolute”.

offX

values: any integer number.
If folowMouse=true , set the calendar position at x pixels from the mouse position. Defaults to 10.

offY

values: any integer number.
If folowMouse=true , set the calendar position at y pixels from the mouse position. Defaults to -10.

formatInputs (see functions for more details)

values: 1-3

formatInputs=1

The date returned from the calendar will be filled in one input.

formatInputs=2

The date returned from the calendar will be split in 2 inputs. Input1 will contain the day. Input2 will contain the month and year.

formatInputs=3

The date returned from the calendar will be split in 3 inputs. Input1 will contain the day, Input2 the month and Input3 the year.

formatSplitter

values: any valid character.
How the returned date should be split. Eg. formatSplitter=”-” will return the date string as day-month-year.
Defaults to “/”.

monthFormat

values: “mm” or “mmm”.
“mm” returns the month in digit format(Eg. ‘01′ for January), “mmm” will return the month in literal format(Eg. ‘Jan’ for January). Defaults to “mmm”.

yearFormat

values: “yy”, “yyyy”.
“yy” returns the year in 2 digit format(Eg. ‘07′ for 2007) , “yyyy” will return the year in 4 digit format (Eg. ‘2007′ for 2007). Defaults to “yy”.

elToAppend

values: the id of the element you want the calendar attached to.

Defaults to document’s body. Only counts if folowMouse=false.

callNotice

values: the name of the function to call.
If you wish to add a callback to another function after a date get’s selected use this option. Accepts any function but you can’t use parameters.
Eg.

to call the ‘alive’ function below, just add to the flags area callNotice = “imalive()”. It wil be called each time a date get’s selected.

function alive(){alert(’I\’m alive!’)}

FUNCTIONS:

fPopCalendar(param1, param2, param3)

param1, param2, param3: are the input ID’s to be filled with the returned date from the calendar.

param1 is mandatory for all formatInputs options.
if formatInputs=2, the param2 is mandatory, and it will represent the second input.
if formatInputs=3, param2&param3 are mandatory, and will represent the second and third input.

SETTINGS/INSTALL

1. Download the zip file and put the js and css files in your working directory.
2. Include the files in the template you wish to use the calendar. If you use the default settings they should look similar to this.

Eg.

<script type=”text/javascript” src=”calendar.js”></script>
<style type=”text/css” media=”all”>
@import url(cwcalendar.css);
</style>

3. If you wish to customize the calendar add the flags&options before you include the JS:
Eg.
<script type=”text/javascript”>
itype = “strict”;
imaxDays = 650;
</script>
<script type=”text/javascript” src=”calendar.js”></script>

4. Enjoy.

Download Download

Trackbacks & Pings

  1. Javascript Calendar Widget v1.07 at Tools and how to’s on 19 Nov 2007 at 2:14 pm

    [...] is just un update for the original calendar script. It includes the american date format(year-month-day). It’s also the default setting now so [...]

Comments

  1. TJ wrote:

    Hi question for your calendar. How will I have the Sunday as the first start date. And how which line do I need to change so that Saturday cell show up as regular week day.
    Thanks in advance.

  2. Chris wrote:

    Hey, I’ve been testing your widget for use in my site and I like it quite a bit.

    I’m no js guru but I came across one issue when navigating the years…it would move from 2006 to 20061, 200611, etc. Looks like a variable type problem. I added a hack after line 506:

    cw.selYear = parseInt(cw.selYear);

    Being in the US, I wanted to convert the date format to mm/dd/yyyy. So I changed some stuff around with the output and used the “formatType” option which I’m guessing was intentionally undocumented.

    I think you could have a fairly popular add-in if you continued working on it.

    Oh, I also get a deprecation warning from the use of the captureEvents method.

    I would also think about porting it to use the jquery library. It’s becoming more and more popular and would definitely get you more awareness.

    Thanks!

  3. adisan wrote:

    Hi Chris,
    yep the “formatType” was left undocumented, because at the moment it’s a big function that takes care of formatting the ouput in input fields(1 to 3), but I’ll release a new version pretty soon that will take in consideration the order of date fields too.
    For a total non JS webmaster who wants to use the calendar, it wasn’t quite a good idea to tell him “change the xxx line from the JS to…”.

    As for the “captureEvents” method, well, not everybody uses ie7 or ff2, to my dissapointment, so I had to take in consideration older browsers too, from IE5.5, IE6…, or Mozilla.

  4. amin2u wrote:

    As for temp solution, could you just tell me at what line to format the output?

  5. Brian wrote:

    Hi

    There is an error at line 230. Currently, this reads
    tmpD = this.stDay;

    which produces an error on short periods in strict mode. The line should be
    tmpD = imaxD;

  6. adisan wrote:

    thanks for reporting it

  7. Doğan Kıcalı wrote:

    Place

  8. Robert wrote:

    Hi, I’m wondering about have a calendar picker that returns the date with only DDMM (european stile without year).

    Additionally I’d like
    - to limit the pick to FRIDAYS only
    - DISABLE future dates.

    Is this calendar picker able to do all above jobs?

    Thank you for any tip, help and answer.

    Robert

  9. Robert wrote:

    P.S.

    what about having this format:

    YYYYMMDD

    does the “formatType” option work for this?

    This would also reply to one of my above questions

    obtaining DDMM format (without year digits)

    Thank you

    Robert

  10. Pierre wrote:

    this date picker is great. but when I’m setting yearFormat = “yyyy”, I get the same issue as comment 2 from Chris, the year goes from 2007 to 20071, 200711 etc.
    The hack doesn’t seem to work for me. It would great to resolve this issue.
    Many thanks, Pierre

  11. adisan wrote:

    solved the invalid Year browsing… It leaps fine now back and forth between years

  12. lifeless wrote:

    Hi, under which license this calendar is released ?
    if it is a gpl one, have you considered merging your project with this one: http://www.meanfreepath.com/javascript_calendar/index.html
    which is gpl licenssed.
    and http://felix.plesoianu.ro/js/fcp_calendar.html
    which is released under the MIT license.

  13. lifeless wrote:

    i think that if you all merge your projects you’ll be able to make a good open source alternative to zapatech calendar which is the best available

  14. adisan wrote:

    what do you mean by “you all”?

  15. johns Wilm wrote:

    install notes are not intuative.

    I have installed many of these types of things and it does not work for me. (javascript error).

    should be some mention of link building:
    Show Calendar

  16. adisan wrote:

    what exactly does not work for you?
    The link building I guess it’s pretty intuitive: just call the JS function with the params from the documentation..
    eg src=”javascript:fPopCalendar(param)”…

  17. Chris wrote:

    Really cool… Thanks. I am assuming that the ‘FormatSplitter’ will allow a person to change the date format to mm/dd/yyyy

    I’ll be back to read more on this but wanted to kick the question out since that particular format is what I need for my form. TIA. :-)

  18. Anu wrote:

    Hi there,

    I really like your calendar widget. Wondering if there is a way to add time input to it.

    Thanks.

  19. Chris wrote:

    Need some novice level help. :-) As I use the recommended:

    @import url(cwcalendar.css);

    followed by:

    Choose

    I get the ‘choose’ clickable URL as on the site but it doesn’t do anything (i.e. open a calendar, etc). What am I doing wrong? thanks

  20. Chris wrote:

    Above code didn’t post properly, at any rate, I’m having a difficult time in getting a pop up calendar using the instructions above and am wondering if there might be a more detailed code example. thanks

  21. adisan wrote:

    you have to give me more feedback on what are you trying to do. Please mail me at adi@codetale.com and tell me what you did so far.

  22. ben wrote:

    I’m facing the same struggle as Chris… an example of how to build the form and link would be most helpful. Viewing the source for this page reveals nothing, of course. The only guide I have is:

    choose

    And that tells me nothing useful….

  23. adisan wrote:

    the link should be a javascript action. for example <a href=”javascript:fPopCalendar(’data1′)”>pop</a>

    Where data1 is the id of your input. in my case the input id is data1. <input type=”text” id=”data1″ name=”data1″ />

  24. liny wrote:

    hi friends

    Fine

    @import url(cwcalendar.css);

     Due Date:

    choose

    is not working. i have calendar.js in the same directory. what are the other requirements? pl. help

  25. adisan wrote:

    Hi liny
    1. did you imported the javascript in your HTML file?
    2. I’ve noticed that you used the IE dom format for object refference. I assume you have a form named dateform, and a text input named DueDate. If you give your text input an id called DueDate and put fPopCalendar(”DueDate”) it will work. You need to put only the id of your object, not the object’s reference.

  26. Bo wrote:

    Hi,
    Thanks for the script! It’s going to make things alot easier. I do have one question though.
    When I paste the html in my form and preview it it works great! But when I go to paste the code again (from – to dates) the “to” date that is picked appears in the first (from) box. I hope I explained that right. Any help would be greatly appreciated.

    Thanks,

    Bo.

  27. adisan wrote:

    have you checked for the id’s to be unique? You might have both inputs with the same id.

  28. Bo wrote:

    Hi,
    Thanks! That was the problem. One more question though. When I (on a MAC) click on the text field the calendar pop’s up right beside the mouse. However, when someone using a PC clicks on it, it appears at the bottom of the page.
    I checked the code and adjusted distance from mouse but that did no do it. Any ideas?
    Thanks again!

    Bo.

  29. Patrick wrote:

    Sorry for being an idiot, but did anyone answer the question regarding mm/dd/yy (US Style) formatting. What exactly does formatType have to be set to in order to get this output style returned?

  30. adisan wrote:

    formatSplitter=”/”;
    monthFormat=”mm”;
    yearFormat=”yy”;
    formatType = monthFormat+formatSplitter+yearFormat+formatSplitter+”dd”;

  31. adisan wrote:

    @Bo
    I don’t have a Mac to test it, so I don’t know what to say. It should work on any Firefox/IE engine, but maybe Safari needs some extra code…

  32. Glo wrote:

    can I use this calendar with commercial application?

  33. oyunmac wrote:

    Sorry for being an idiot, but did anyone answer the question regarding mm/dd/yy (US Style) formatting. What exactly does formatType have to be set to in order to get this output style returned?

  34. Morinek dizayn wrote:

    is not working. i have calendar.js in the same directory. what are the other requirements? pl. help

    thanks

  35. wang wrote:

    test

  36. star wrote:

    Hi!
    I’m very new in this whole game. So my question might sound silly but please remember the day when you started. : )
    I made a form in DW and would love to have the calendar in the date field, which is a simple textfield right now.
    I downloaded and put the files in the working directory. And now what?
    Where do I put the code – do I have to do anything else!?
    I would be so pleased to hear from you! It is highly appreciated.

    Thank you

  37. adisan wrote:

    @star

    You need to include the javascript in your document. Then, put this line on your textfield: onclick=fPopCalendar(’idofmytextfield’). Where idofmytextfield must be the id of your textfield where you want the calendar to autocomplete the date.
    Eg. input type=’text’ id=’theid’ onclick=’fPopCalendar(”theid”)’

    Good luck:)

  38. Benoît wrote:

    Hi,
    I’m french and I just want to thank the author for this wonderful script.
    Congratulations !

  39. Mike wrote:

    I would love to include your awesome calender widget in my clients booking form page, pls note, I am fairly new to JS. and seem to be having the same troubles as others have installing the code, I have setup a test sample page with the JS included in the code. an input field, and href link, as mentioned to others, see calender.php, any help with setup would b appreciated
    Regards Mike

  40. adisan wrote:

    @Benoît

    Thank you.

    @Mike
    1.Your file looks very wierd. Check for the html encoding type. Instead of quotes/double qoutes i see non ascii characters in your page source.
    2. Where is the js file uploaded? I checked here http://haresync.com/hatchngrow/calendar.js but it says file not found…

  41. cosinus wrote:

    It’s very beautifull and usefull….nice. Great job !!!

  42. Rodney wrote:

    Thanks very much for providing this calendar widget – I have used it on my site on this page:
    http://www.walnutcreek911calls.info/fcgi/search.cgi
    (My site is still under construction.)
    And linked here on the “About” page to give credit.

  43. Ash wrote:

    hi, It is a great widget and v useful too.

    I have a small prb …i want to show this as a modal dialog, can you help me ? I have a Textfield and a calendar button in a table and when m invoking this calendar , it is getting displayed at the end of the table. My requirement is, that it should be displayed as a separate dialog just below the cal button.

    Thanks!
    Ash

  44. Mitch wrote:

    There a minor problem that causes a problem in safari;
    backB.innerHTML = “&laquo”;
    should be
    backB.innerHTML = “«”; with the semi-colon. Nice widget :)

  45. Mitch wrote:

    That didn’t quite get posted right: &laquo needs a ; at the end

  46. Dave wrote:

    Hi. Great widget!! Thank you. Is it possible to make the format yyyy-mm-dd?
    Cheers

  47. jason wrote:

    very cool :) thanks for sharing with us.

  48. Ashish wrote:

    Could we get rid off the button and popup calendar should be closed when clicking anywhere outside this window. This will make the window shorter too.

  49. Ashish wrote:

    Could we get rid off the “close” button and popup calendar should be closed when clicking anywhere outside this window. This will make the window shorter too.

  50. Sophia wrote:

    Hi.

    I need help.

    I have added the files to my working directory, and added the following into the page where it is to be seen.

    @import url(cwcalendar.css);

    Start Date:

    However, the calendar does not appear, and the page shows as a broken link.

    Did I do anything wrong?

  51. Sophia wrote:

    I have taken out the to show you what I have typed.

    script type=”text/javascript” src=”calendar.js”/script
    style type=”text/css” media=”all”
    @import url(cwcalendar.css);
    /style
    b Start Date: /b input type=”text” id=”date1″ onclick=”fPopCalendar(’date1′)” /

  52. adisan wrote:

    make sure the rest of the files(css file and js file) are on the path you specified.

    cwcalendar.css and calendar.js should be under the same directory as your page in this case.

  53. Ronald wrote:

    Hi, great work!.A question…how can I change the color of the Saturday day of October?..

  54. Damien wrote:

    This Calendar really works nicely. One little fix on the calendar.css would be to use
    #calendar ul {
    list-style-type: none;
    margin:0;
    padding:0;
    }

    instead of
    ul {
    list-style-type: none;
    margin:0;
    padding:0;
    }

    Without it some people may have trouble with other lists on the page not displaying as expected.

    One of my newbie programmers spent forever trying to understand why the lists he was creating wouldn’t display the way he wanted.
    :)

  55. Scott wrote:

    just a going through this I am looking for a way to go backwards on the year. there is a forward button but no reverse

  56. bonatoc wrote:

    Hi Scott, this is just under Safari (maybe other browsers). You have to replace

    backB.innerHTML = “&laquo”;

    with

    backB.innerHTML = “«â€;

  57. bonatoc wrote:

    Sorry, the character is interpreted by the “posts” displayer. Just add a semicolon after “&laquo”, INSIDE the quotation marks.

  58. theophilus wrote:

    What a great widget! Thank you so much for all your work. Is there a way to add a “today” option to it, perhaps at the bottom.

  59. Peps' wrote:

    Hi,

    Great job !!
    I would just want somebody to confirm (or not !!) that this should work (because it does not at my home):

    @import url(cwcalendar.css);

    Cliquer ici

    .htm, .js and .css are in the same folder

    Thanks a lot

  60. adisan wrote:

    if you add a javascript function to a link element under the href attribute you must tell the browser that… The correct href attribute is “javascript:fPopCalendar(’data1′)”;

    Hope this helps:)

  61. n8 wrote:

    i’ve read throught the thread and have tried all the hacks:
    everytime i change yearFormat to “yyyy”, the widget give me a one digit year between the <> with no days on the calendar…

    ??? i’m stuck…please advise

  62. mansoor wrote:

    this is mansoor from india using ur calandar

    its grate.. working fine..

    In my software there are many date selections in single page, and whenever i choose it for blank text boxes, iwant the calendar to show current date, and if the date is already filled the already selected date should be shown in calendar??.. that is it does not reset for blank textboxes

    is there any fascility to do these in ur calendar??

    pls let me know..

    waiting for yoyr reply
    thanks in advance

  63. [tokenizer] wrote:

    First of all! Great job!

    Here are some comments and suggestions. =)

    Bug: I am seeing the same problem with n8(comment no 61).Seems like the script in popping up the calendar is limited to the default format.

    Functionality: I suggest it would be better if the calendar closes when it is outside of focus (e.g. user clicks outside the calendar). This will be more desirable for better user experience. (Just as what was suggested by ashish in comment no. 48-49)

    This is just a suggestion anyway. Great job man! Cheers.

  64. [tokenizer] wrote:

    TIP: Changing the start of the week to Sunday.

    1. Change Line 104 from

    var DayCol = new Array(”M”, “T”, “W”, “T”, “F”, “S”, “S”);

    to

    var DayCol = new Array(”S”,”M”, “T”, “W”, “T”, “F”, “S”);

    This will change the header to start at S (Sunday).

    2. Comment lines 189 and 190;

    From

    iFirstDay–
    if(iFirstDay<0){iFirstDay=6}

    To

    //iFirstDay–
    //if(iFirstDay<0){iFirstDay=6}

    This will synchronize the day value with the header.

    Voila! Your widget now starts in Sunday! :D hope this helps.

  65. Rathika Krishnavelu wrote:

    Hi,

    Very nice Calender.

    I have a requirement. In that calender the user should not Select Saturday and Sunday. How to Disable Saturday and Sunday while Clicking the Calender itself.

    Thanks in Advance.

    Thanks & Regards,
    Rathika Krishnavelu

  66. Banggo wrote:

    Thanks!!
    It works just fine and so easy to use, but maybe I’ve to change the format to dd-mm-yyyy because i use it in indonesian format.
    thanks, anyway!

  67. adisan wrote:

    @Rathika Krishnavelu
    Here is an update of the calendar that has the option to disable saturdays and sundays.
    http://codetale.com/2009/06/21/javascript-calendar-widget-108/

  68. Charles Naccio wrote:

    Thanks! I needed this for a client project we were working on. Works perfect.

  69. saad wrote:

    The calendar widget is very good. I have 2 requests,

    I wanted to enable the date selection to be valide only from Today and forward dates i.e. I don’t want the person to select previous date(i.e. yesterday or any previous date). I tried setting

    itype = “strict”;
    startDay = new Date().getDate();
    startMonth = new Date().getMonth();
    startYear = new Date().getFullYear();

    What else do I need to set, as it doesn’t work in this case?

    One more thing is, I want to return the appended Day with date as well, e.g. “Sat 10/09/19″

    How to achieve this? Thanks in advance.

  70. saad wrote:

    sorry to bother in the above first question about date range….resolved by your example: http://codetale.com/cwcalendar/examples/maxdays.html

    But, i still need to figure out, how to return DAY as well with date.

  71. saad wrote:

    Resolved that issue as well

    to set range of date, i set (from your example)
    var itype = “strict”;
    var imaxDays = 364000;
    var startDay = new Date().getDate();
    var startMonth = new Date().getMonth();

    and for appending day, In calendar.js
    function fillBackDate(){

    dayIs = new Date(tYear,tMonth,tDay);
    val = dayIs.getDay();

    if(val == 0)
    dayIs = “Sunday”;
    else if(val == 1)
    dayIs = “Monday”;
    else if(val == 2)
    dayIs = “Tuesday”;
    else if(val == 3)
    dayIs = “Wednesday”;
    else if(val == 4)
    dayIs = “Thursday”;
    else if(val == 5)
    dayIs = “Friday”;
    else if(val == 6)
    dayIs = “Saturday”;
    else
    dayIs = “ERR”;
    }
    and than in the same function below

    if(formatInputs==1)
    {

    //changed this line document.getElementById(elem1).value = dayIs +” “+tDay + formatSplitter + tMonth + formatSplitter + tYear;

    }

  72. Roberto wrote:

    I’m trying to use the calendar with an asp TextBox, but i cannot make it run. and always get the following error.

    Microsoft jScript runtime error: Object required

    thx

  73. Geoff Champion wrote:

    Further to my last – Could I call an intermediate function which sets iDay, iMonth and iYear appropriately before calling fPopCalendar?

  74. adisan wrote:

    Hi Geoff,

    Yes, you can implement your own function and call it on the same action. For example the onclick action can support 2 function calls, that are executed one after the other. So you could make something like onclick=’somefunction();fPopCalendar()’, or you can append the function straight in the calendar script on the fPopCalendar() function right in the first lines of the functions.

    Hope this helps,

    Adisan

  75. Lovely wrote:

    Hi! Is there a way that the date for next month will not be highlighted? because I’ve noticed that when you click on next month, the day which is the same as today is still highlighted.. Please figure it out. thank you.

  76. vol7ron wrote:

    @Lovely:

    This is one of the bugs that I’ve fixed. I’ve also done the same for the year.

    Additionally, another feature I’ve added shows the previous selected date and gives the user the option of turning this feature on/off.

  77. pipedragon72 wrote:

    loving the calendar. the site i’m building has an arrival and a return date picker on the same page. how can i add the calendar in as it won’t work for both separately; do i need to copy and rename it or something?

Post a Comment

Your email is never published nor shared. Required fields are marked *

*

*