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
You can use Date object:
var d = new Date(),
current = d.getFullYear();
Code for simple select box would be this:
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
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.