View Full Version : Why does this code return the year 2006 instead of the current year?

09-19-2005, 10:03 PM
I am hoping that someone can point out the error that is causing this to go to the year 2006 instead of 2005

<script type="text/javascript"><!--
function getCorrectedYear(year) {
year = year - 0;
if (year < 70) return (2000 + year);
if (year < 1900) return (1900 + year);
return year;}
var today = new Date();
var d = today.getDate() + 1;
var m = today.getMonth() + 1;
var dateString = y + '-' + m + '-' + d;
var y = getCorrectedYear(today.getYear());
this.reservation.iyear.value = y;
this.reservation.iday.value = d;
this.reservation.imonth.value = m;

Once the date is set in the browser window it is submitted using this button and code.

href="http://getdors.com/dors/dorsindex1.php?page=checkdeal&system_id=80&this.reservation.dateString"><img src="images/button-hotdeals.gif" vspace="0" border="0"></a>

But it does not seem to get the date that is entered in the form. The site can be seen in action at http://www.capecodderresort.com the function is on the right hand side of the screen.

Thank you for your help.

09-19-2005, 11:05 PM
When I viewed the website, the day, month, and year were correctly filled out for the input fields. It showed the year 2005 for the iYear input field.

However, the JavaScript is executed on the href string for the link immediately, which sets it for the current date. When you click the link to submit the form, the button never changes it's own href string to reflect the values in the input fields. It uses the date set when the page was loaded. You need an onClick event that changes the href string to reflect the new changes in the form.

I'd eleborate and maybe write a quick function if it wasn't time to leave work, hehe. Hope someone can help you more if you don't understand.


09-20-2005, 06:06 AM
It depends on the client date. The date settings must have been set to 2006. And you don't need the getCorrectedYear() function. Just use getFullYear() and not getYear() to always get 4-digit years.

var y = today.getFullYear();