View Full Version : JS Calendar Script Help

05-15-2006, 12:41 AM
script: http://www.dynamicdrive.com/dynamicindex7/jasoncalendar.htm

I've been really pleased with this script except for one small issue, and I have to say I am not familiar enough with javascript to trace it.
When a user enters their "year" into the year field (ie types it in) it doesn't register in the script unless they press enter or unless they use the calendar object.

Is it possible to alter the script in anyway to either grey out the year box and force the user to select the calendar object or, preferably, for the script to take the year when the the year field loses focus?

Thanks in advance

05-15-2006, 01:23 AM
I'm no sure I understand. On the demo page if I click this button:

<input type="button" onClick="alert(this.form.orderdate.value)" value="Show date value passed">

which clicking on is not hitting 'enter', the value I typed into the year field is shown. I guess I'm a little vague on what you mean by 'use the calendar object'. I can do this in the address bar:


and it accurately reports any typed in change to the value of the second year field on the page. ([1][3] will get the first one) Just exactly what isn't this doing for you?

Please post a link to the page on your site that contains the problematic script so we can check it out.

05-17-2006, 07:01 PM

As an example if someone has a due date of January 28th 2007
they select January and the day (28) from the drop down boxes.
then if they type 2007 in the text box (next to the calendar object) but they don't press enter after typing in 2007, and if they don't use the calendar object then the script still takes the year variable as being 2006.

this is evidenced in the html coding provided on the result page

I believe I need to add an "onLostFocus" statement but I'm not 100% sure as to what it should say or where I should place it.

05-17-2006, 07:34 PM

I added this:

onChange="' + DateName + '_Object.fixYear(this)"
to this:

writeln('<input' + InitialStatus + ' class="calendarDateInput" type="text" id="' + DateName + '_Year_ID" size="' + eval(DateName + '_Object.picked.yearPad.length') + '" maxlength="' + eval(DateName + '_Object.picked.yearPad.length') + '" title="Year" value="' + eval(DateName + '_Object.picked.yearPad') + '" onKeyPress="return YearDigitsOnly(window.event)" onKeyUp="' + DateName + '_Object.checkYear(this)" onBlur="' + DateName + '_Object.fixYear(this)">');