Javascript dynamically adds data items to the drop down list

  • 2020-03-30 03:03:40
  • OfStack

Javascript adds data item.html to the drop-down list
 
<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
<title> Dynamically add data items to the drop-down list </title> 
<script type="text/javascript"> 
function gel(id) { return document.getElementById(id); } 

window.onload = function() { 
var cbbYear = gel("mysel"); 
for (var i = 1990; i < 2014; i++) { 

//Method 1
 

//Method 2
var opt = new Option(i, i); 
cbbYear.options.add(opt); 
} 
}; 
</script> 
</head> 
<body> 
<select id="mysel"> 

</select> 
</body> 
</html> 

Related articles: