Saturday, 24 August 2013

add item to dropdown list in html using javascript

add item to dropdown list in html using javascript

I have this javascript+html to populate a dropdown menu but it is not
working, am i doing anything wrong? Note I want the drop down menu to be
filled on page Load
<!DOCTYPE html>
<html>
<head>
<script>
function addList(){
var select = document.getElementById("year");
for(var i = 2011; i >= 1900; --i) {
var option = document.createElement('option');
option.text = option.value = i;
select.add(option, 0);
}
}
</script>
</head>
<body>
<select id="year" name="year"></select>
</body>
</html>

No comments:

Post a Comment