Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Why does this code return the year 2006 instead of the current year?

    Greetings,
    I am hoping that someone can point out the error that is causing this to go to the year 2006 instead of 2005

    Code:
    <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;
           //--></script>
    Once the date is set in the browser window it is submitted using this button and code.

    Code:
     <a
          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.

  • #2
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    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.

    -Shane

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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.

    Code:
    var y = today.getFullYear();
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •