Home
Google
 


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.

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:)

Post a Comment

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

*

*