Home


Javascript Calendar Widget 1.08

Due to popular request, here is another minor update to the calendar that contains flags to setup Sunday as the first day of the week, and options to disable Saturday and Sunday, and since many complain that the first post containing the setup is confusing, here are the full options available for the calendar. Remember, all of this flags are optional, but must be defined before your include the javascript file.

click here to download the calendar

DESCRIPTION
This script is meant to be used as a date picker or date display.

SETUP
All the flags below are optional. Define only what you need!. You can find some calendar examples at the bottom of the page.

iMonth
Option: defines the default month for the calendar
Values: 0-11 (January – December)
Default: PC date.

iYear
Option: defines the default year for the calendar
Values: Year, 4 digits format
Default: PC date.

iDay
Option: defines the default day for the calendar
Values: 1-31
Default: PC date.

itype
Option: See the description below regarding imaxDays,stDay,stMonth,stYear
Values: “strict” or “loose”
Default: “loose”

imaxDays
Option: days can be selected only on this range of days (specified by a number) starting with startDay,startMonth,startYear(see below). imaxDays only counts if itype is “strict”.
Values: >0

startDay
Option: enable date selection from this day forward counting imaxDays
Values: 1-31
Default: iDay.

startMonth
Option: enable date selection from this month forward counting imaxDays
Values: 0-11
Default: iMonth.

startYear
Option: enable date selection from this year forward counting imaxDays
Values: year, 4 digit format
Default: iYear.

saturdayOff
Option: Disables selection for saturdays (this is independent from imaxDays and itype)
Values: true/false
Default: false

sundayOff
Option: Disables selection for sundays (this is independent from imaxDays
and itype)
Values: true/false
Default: false

sundayFirst
Option: Displays the calendar with sunday as the first day of the week.
Values: true/false
Default: false

offX
Option: x distance from the mouse for the popup calendar
Values: >0
Default: 10.

offY
Option: y distance from the mouse for the popup calendar
Values: >0
Default: -10.

formatSplitter
Option: date separator
Values: string
Default: “-”.

monthFormat
Option: month format on the input. June will be displayed as “Jun” in “mmm” format or as “06″ in “mm” format.
Values: “mmm” or “mm”
Default: “mm”

yearFormat
Option: year format on the input. 2009 will be displayed as “2009″ in “yyyy” format or as “09″ in “yy” format.
Values: “yyyy” or “yy”
Default: “yyyy”

callNotice
Option: Call a function when a date is selected
Values: “function name”
Default: “fallsilent()”

click here to download the calendar

EXAMPLES
A simple example that formats the date output to yy/mmm/dd
An example that sets sunday as the first day of the week
An example that enables date selection for this year.
A simple example that disables date selection for weekend days.
A simple example that calls a custom function when a date is picked.

Enjoy!

P.S. Since the old versions of the calendar gathered more than 5.000 downloads, I’m curious how people use it. So, if you have used the calendar on a public page, please leave a comment with the link where you have it running so it can be used as examples for others.
Thanks:)

L.E I’m also open to sugesstions, features & bugs you might find.

Trackbacks & Pings

  1. javascript calendar widget at Tools and how to’s on 21 Jun 2009 at 5:20 pm

    [...] THIS VERSION IS NOW DEPRECATED. THE NEW VERSION CAN BE FOUND HERE [...]

Comments

  1. Peter wrote:

    Adi,

    I am trying to format the out to mm/dd/yyy, how can I do this? I’ve tried to change the formatType. It work the first time, but when you click again to pop up the calendar, the year and dates are not display correctly. Please help. Thanks.

  2. adisan wrote:

    @Peter

    I have modified the script so it supports the dateformats defined by formatType. It’s in a separate file because I didn’t had time to test it properly but it should work ok. Below is the link to the temp file.

    http://codetale.com/cwcalendar/calendar_ftype.js

  3. Howard wrote:

    So, why am I not able to scroll the year backwards to select dates in previous years… also once I scroll forward in the years, I am not able to move backward… am I missing something?

  4. adisan wrote:

    @ Howard

    fixed, thanks for letting me know.

  5. vivek wrote:

    Hello Adisan

    Thanks for writing such a wonderful tool.
    I wanted to change the date format to mm/dd/yyyy. for that I went and got the script, http://codetale.com/cwcalendar/calendar_ftype.js but still the format is showing as (yyyy-mm-dd), I also tried to change the formattype, but that did not help either. Please help.

    Thanks
    Vivek

  6. adisan wrote:

    @ Vivek,

    Thanks, updated the live version in the meantime, so you can download the zip. You might wanna look here for an example(this example is also found in the zip file):
    http://codetale.com/cwcalendar/examples/dateformat.html

    If you delete this line “var monthFormat = “mmm”;” and add this line “var formatType = monthFormat+formatSplitter+”dd”+formatSplitter+yearFormat;” at the end of the vars declaration it will format the calendar to your needs.

  7. rash wrote:

    hi,

    I like your calendar..

    I am trying to use like this version in my php codes

    but its not showing anything

    can u help me pls?

  8. peter wrote:

    Thanks for your nice calender.

    Is there a way to close the calender on mouseout? I mean when you move your mouse off the calender.

    peter

  9. adisan wrote:

    @rash

    hi, I can’t help you unless you tell me/give me your code to see what are you trying to do:)

    @peter
    nope, but since it’s open source you can write a small plugin for that or ask a JavaScript coder to that for you.

  10. Venki wrote:

    I am using IE8 browser and the calendar pop up positions are improper. Is it a IE bug or get position script code need any alteration?

  11. Venki wrote:

    I figured it out.
    Changed the following:
    browser==”Windows Internet Explorer”
    Thanks

  12. adisan wrote:

    tnx Venki,
    Will include it in the next update.

  13. Rama wrote:

    This is a wonderful calendar. Our customers liked it. They are asking me; if I can make it a inline calendar meaning, always show the calendar on the webpage. I tried, I could not. Can we do that with this calendar?

  14. adisan wrote:

    @Rama,

    Yes you can. The onlly problem is that you can’t have more than one calendar on the same page.

    The first thing to do is to open the css style and do the folowing:
    remove position:absolute for #calendar;
    add a new line at the bottom #closeBtn{display:none}

    In your html, where you want your calendar to appear, create something like this
    <div id=”calendar”></div>
    <input type=”hidden” id=”elem” name=”elem”/>
    <script type=”text/javascript”>
    fPopCalendar(’elem’);
    </script>
    Here is an example page: http://codetale.com/inline/

  15. Clat Giles wrote:

    V 1.08 When the itype is set to strict the and you pass it a value for imaxDays instead of the default, the script does not always block out dates beyond the imaxDays number of days from today. This is true today, if you pass the imaxDays as 4 or any day of the month in September before the 17th. I believe it is a bug in the getEnd() function.

  16. John G wrote:

    Adi,

    First let me say that this is by far the best, most flexible calendar script available. And I think I have tried most. Thank you for making it available. Great for using with PHP classes to enable users to define date formatting etc.

    Just a suggestion – when a user clicks on the calendar textbox before the page loads an error is thrown. Just a couple of if statements fixes it.

    After line 411 insert:
    if (document.getElementById(el) {

    Before end of this function add: }

    Line 476:
    Change to (document.getElementById(’calendar’)) ? document.getElementById(’calendar’).style.display=”block” : null;

    Line 478:
    Change to: if (folowMouse && (document.getElementById(’calendar’)) )

    How this helps someone. (Not tested in IE or other browsers)

  17. adisan wrote:

    Thanks John,

    Will take a look and fix it. For the moment I’m only gathering suggestions and bugs, since I’m moving everything to a new domain and will re-do the whole calendar to support multiple calendar instances, each with their own defined options.

  18. Leslie wrote:

    I love your calendar widget, but most of the time I use the Tab button to go from field to field in a form and the calendar doesn’t popup, when the cursor moves into the designated field.

    I tried changing the ‘onclick’ to ‘onfocus’ and that worked except the calendar popped up clear over where I had positioned my mouse cursor, instead of next to the field that had the focus.

    Is there a way to get the calendar to position itself next to the field that has the focus?

  19. Animesh Mondal wrote:

    Hi,
    The calendar control is very well organized. The only hindrance I’m facing in selecting years of very long past(e.g. 1950). We need to do a lot of clicks on the year navigation control. So, is there any way around to get rid off this?

    Thanks,
    Animesh.

  20. Faddoul wrote:

    Hi Adisan,

    Thanks for this calendar. I’m using it in a intranet. I have a problem since 1/1/2010 that I can go back by year. I mean the laquo symbol is not displayed. This behavior occurs only when using the chrome browser.
    I thought I did something wrong, but when trying your samples, I get the same result.

    Thanks,
    Faddoul

  21. Faddoul wrote:

    Sorry I got it working after i downloaded the new version. I think your you need to update your samples with the latest version :)

  22. Roy Low wrote:

    Great widget!
    Congrats on using simple code so that mere mortals can understand and modify.
    An option to position it relative to the window – a % option would be great. To center it I used
    ‘document.getElementById(”calendar”).style.left = “40%”;’ in the callNotice function. A bit of a hack!

  23. Bman wrote:

    I have also run into the problem with imaxDays not working, we are trying to feed a date into the control and have users pick a day within a week of that start date and we cannot make this work at all. Other than this issue the calendar rocks, we do not want to pull it out of the rest of our site for this one little bug.

  24. adisan wrote:

    Hi Bman,

    Can you show me an example where you have this problem?

  25. Bman wrote:

    Here is the setup script, it doesn’t throw an error you just do not get the correct days available to be chosen in the control. The idea is to input a start date for a single week and allow the user to chose any day within one week of the start date.

    var formatSplitter = “-”;
    var monthFormat = “mm”;
    var yearFormat = “yyyy”;
    var itype = “strict”;
    var startDay =07;
    var startMonth = 01;
    var startYear = 2007;
    var iDay =07;
    var iMonth = 01;
    var iYear = 2007;
    var imaxDays = 7;

  26. adisan wrote:

    Hi Bman,

    Indeed there is a bug on my end. I will let you know as soon as I fix it. Thanks for the feedback.

    Adrian

  27. adisan wrote:

    @Bman,

    Fixed and re-uploaded the zip file. It should work well now.

    Adrian

  28. Bman wrote:

    Hey Adisan, you rock, works like a charm now, thank you very much!

  29. Ayo wrote:

    how do you solve the multiple entering of this widget on a single webpage.

    for example if you a dateOfBirth input box and and inputbox called date, the widget only works for the first input box not the second input box.

    thank,
    Ayo.

  30. Ayo wrote:

    it working okay it was my mistake the html form seem too long therefore it display at the bottom of the unseen section of the page.

    thanks alots if i make millions of dollars i will surely remember you.

  31. Ayo wrote:

    My only problem is the date formatting how can i change the format to dd/mm/yyyy UK style instead of the default american style. pls provide a sample i have done everything within the formatting section of the script i embedded within my htlm tag.

    thanks,

    Ayo.

  32. Sam wrote:

    Great stuff, but i seem to be having a little problem. I have 2 date fields on my form next to each other, the widget seems to populate just one of the fields, when i try to populate the 2nd one it changes the content of the 1st.

    I’m i missing something?

    Sam

  33. adisan wrote:

    You need to specify for each of the instance the id you want to be filled back.

    Eg, you have 2 inputs with the ids id1 and id2, id1 should have onclick=’fPopCalendar(”id1″)’ the second one should have onclick=’fPopCalendar(”id2″)’.

  34. Rantu wrote:

    Hey Adisan

    Great calendar!

    I wanted to include multiple it in multiple text boxes in a single page. But, it requires the id to be ‘date’; so not possible.

    Probably, you can add this feature in next release.

    Anyways, thanks for sharing.

  35. Sam wrote:

    Brilliant!!!!

  36. adisan wrote:

    Hi Rantu,

    Now it doesn’t. You can specify the id’s yourself. For example you can put the first input to have the id=’date1′ the second ‘date2′ etc. You append the calendar to the input by specifying the id you want the calendar to fill back. For the first input you add onclick=’fPopCalendar(”date2″)’, the second fPopCalendar(’date2′) etc…

    Hope I explained it ok:)

  37. vol7ron wrote:

    Thanks for the post.

    I’ve made a lot of changes to your script, including fixing some bugs and adding some new features.

    I see a lot of room for performance optimization, but I’ve mainly kept the code as-is.

    If you want, I can send it when I’ve finished working on this one feature.

    vol7ron

  38. Bill wrote:

    Hi. I don’t see license information. I’d like to include this calendar (fully credited to you, of course) in an open source project I’m working on. The project is under GNUv3 open source license. Is this permissible? E-mail me for full details if required.

  39. adisan wrote:

    @vol7ron

    Cool, I would like to see what you came up with. And yes, I should optimize my script but didn’t had time for it. The core script was made in half a day, about 4 years ago and it hasn’t been changed since then. I will send you an empty mail with the subject codetale, so if you want, you could reply me to that email with the script.
    Thanks

  40. adisan wrote:

    Hi Bill,

    You can use, alter do whatever you want with the script. I haven’t put any licensing info since I really don’t care on how others use it. You don’t have to credit me for the script neither.

  41. Bill wrote:

    Thanks, adisan.

Post a Comment

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

*

*