RussellHarrower RussellHarrower - 2 years ago 114
Javascript Question

jQuery generate years. for drop down

I came up with a small issue. that am trying to come up with a way to fix it.

Baisclly what I want to do is take 18 years of the year ie: 2011 which returns 1993.
and generate a drop down option for a user to select any year before that.

baisclly they have to show that they are over the legal age of 18.

If you can help that would be great.

Answer Source
var minOffset = 18, maxOffset = 100;

var thisYear = new Date().getFullYear();
var select = $('<select>');

for (var i = minOffset; i <= maxOffset; i++) {
    var year = thisYear - i;
    $('<option>', {value: year, text: year}).appendTo(select);



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download