I am trying to create drop down boxes dynamically, like when I click on add button it has to create new drop down box. And drop down list also contains dynamic values like it needs to take current year and has to show up to plus five years. please suggest me to do this.
Thank you..
Here is the code that I tried.
javascript code:
function Add()
{
var name1 = document.createElement("select");
name1.setAttribute('id',"year1")
name1.setAttribute('oncreate',"Date1()");
}
function Date1(){
d = new Date();
curr_year = d.getFullYear();
for(i = 0; i < 5; i++)
{
document.getElementById('year1').options[i] = new Option((curr_year-1)-i,(curr_year-1)-i);
}
}
html code:
<input type="button" name="add" value="Add" onclick="Add();">