www.webdeveloper.com
Results 1 to 2 of 2

Thread: Select next year in getFullYear

  1. #1
    Join Date
    Nov 2009
    Posts
    5

    Select next year in getFullYear

    Hi,

    I have 2 month (monthNow, monthLater) and 2 year (yearNow, yearLater) selects. When a user selects a month from monthNow, monthLater needs to increase by 1. The same goes for yearNow and yearLater. eg If a user selects the 2nd month in monthNow, the monthLater select needs to be the 3rd month and so on. This becomes a problem when it comes to the 12th month as the year then also has to change.

    I need to be able to select the next value in getFullYear. For example I have the code below, which simply fills a select with the full year from now to 2011.

    So if the year selected index is currently 2009, when a user selects the 12th month I need it to change the year to 2010 and so on.

    Basically I just need to know how to select the next value in getFullYear. Any ideas? I hope this make sense.

    var d = new Date();
    currYear = d.getFullYear();

    for(i = 0; i < 3; i++)
    {
    document.getElementById('searchAir.segments[0].departDate.year').options[i] = new Option(currYear+i,currYear+i);
    }

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Like this?:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>untitled</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/javascript">
    onload=function(){
    var d=new Date();
    currYear = d.getFullYear();
    var sel=document.getElementById('year');
    var nrMax=3, opt;
    for(var i=0;i<nrMax;i++){
    opt=document.createElement('option');
    opt.setAttribute('value',currYear);
    opt.appendChild(document.createTextNode(currYear));
    sel.appendChild(opt);
    currYear++;
    }
    }
    </script>
    </head>
    <body>
    <form action="">
    <select name="year" id="year">
    </select>
    </form>
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles