javascript - adding options to select -


hi tried adding options select through javascript in 2 ways, neither worked:

one way:

function addyear() {     var currentyear = new date().getfullyear();     var legalworkingage = currentyear - 16;     var select = document.getelementbyid("year");     (var = legalworkingage; >= 1900; i--) {         try {select.add(new option(i,0), null);} // standards compliant; doesn't work in ie           catch(ex) {select.add(new option(i,0));}    // ie         }//for } //addyear 

second way:

function addmonth() {     var select = document.getelementbyid("month");     (var = 1; <= 12; i++) {         var option = document.createelement('option');         option.text = option.value = i;         select.add(option, 0);     } //for } //addmonth 

i used

<body onload="adddate()"> 

adddate():

function adddate() {     addmonth();     addyear(); } 

html:

<select id="month" name="month"> </select> <select id="year" name="year"> </select> 

any ideas? tnx :d

this work in browsers

live demo

window.onload=function() {   addyear(); }  function addyear() {     var currentyear = new date().getfullyear();     var legalworkingage = currentyear - 16;     var select = document.getelementbyid("year");     (var = legalworkingage; >= 1900; i--) {         select.options[select.options.length]=new option(i,i);     }//for } //addyear 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -