JavaScriptのサンプル(その2)
コンボボックス(タグ名:select)に要素を追加する.
IE,FireFox,Operaにて動作確認
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<script type="text/javascript">
function loadEvent()
{
var combo = document.getElementById('selectYear');
for(var y=2003 ; y<2007 ; ++y){
var text_node = document.createTextNode(y);
var elem = document.createElement('option');
elem.appendChild(text_node);
combo.appendChild(elem);
}
}
window.onload = loadEvent;
</script>
</head>
<body>
<form>
<select id="selectYear"></select>
<form>
</body>
</html>