SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Current & Future Years in a Dropdown Menu

    Hi,

    I'm looking for some Javascript that displays the current year and the next 10 years afterwards as options in a select menu, and that auto updates as the years pass.

    I've looked around without much success, so I was hoping some of you here on Sitepoint could help me out. Any help would be greatly appreciated.

    Many thanks,
    Rob

  2. #2
    Forums Designer
    Join Date
    Jun 2004
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use Date object:

    Code:
    var d = new Date(),
          current = d.getFullYear();
    Code for simple select box would be this:
    Code:
    var d = newDate(), start = d.getFullYear(), text = '<select>';
    for(var i=0; i<10; i++)
    {
       text += '<option value="' + (start + i) + '">' + (start + i) + '</option>';
    }
    text += '</select>';
    
    // do something with text

  3. #3
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for such a swift reply, CyberAlien.

    When it comes to Javascript I'm extremely green-fingered to say the least - could you explain to me where I would place the above elements on my page (including any necessary script tags)?

    Many thanks again for your help.


Bookmarks

Posting Permissions

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