jQuery Generate Years Dropdown Dynamically using JavaScript

Here i'll justify a way to use jQuery to come up with years dropdown dynamically in JavaScript or JavaScript generate years dropdown dynamically.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Generate years for dropdown using jQuery</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function() {
var noofyears = 100; // Change whatever you want to
var thisYear = (new Date()).getFullYear();
for (var i = 0; i <= noofyears; i++) {
var year = thisYear - i;
$('<option>', { value: year, text: year }).appendTo("#ddlyear");
}
});
</script>
</head>
<body>
<form id="form1">
<div>
<select id="ddlyear"></select>
</div>
</form>
</body>
</html>

Previous Post Next Post