64
rated 0 times
[
65]
[
1]
/ answers: 1 / hits: 33584
/ 12 Years ago, tue, february 12, 2013, 12:00:00
I want to populate the year in a select javascript. I did the following code.
<html>
<head>
<script type=text/javascript>
$(document).ready(function(){
var cur_year=new Date().getFullYear();
var obj=document.getElementById(yr);
alert(obj);
for (var i = 2000; i <= 2020; i++) {
opt = document.createElement(option);
opt.appendChild(document.createTextNode(value));
opt.selected = selected;
opt.value = i;
opt.text=i;
obj.appendChild(opt);
}
});
</script>
</head>
<body>
<select id=yr>
<option>year</option>
</select>
</body>
</html>
I don't know what is wrong in this. I want to populate the year and want to select the current year in the select box when the user opens the browser. Any one can help? please!
More From » javascript