newbie: how to create a dynamic select list of the current date + 5 years
Hi - I'm a JSP newbie (coming from a PHP background), and am trying to create a select list that contains the current year, plus 5 years. So, the list when generated (today), would display:
2007
2008
2009
2010
2011
2012
Obviously, the code would need to generate inside the option tags, as well as in the value property of the option tag.
[388 byte] By [
pixelguya] at [2007-11-27 5:18:50]

# 1
function addit(){
var val = 2012; //you can take this from js date object and strip it off
for (var i=2007; i <= val;++i){
addOption(document.getElementById("mycombo"), i, i);
}
}
function addOption(selectbox,text,value)
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}
without hardcoding:
function addit(){
var dd = new Date();
var yearnow = dd.getFullYear();
for (var i=yearnow; i <= yearnow + 5 ;++i){
addOption(document.getElementById("mycombo"), i, i);
}
}
function addOption(selectbox,text,value)
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}
in your jsp:
<body onload="addit();">
<form>
<select name="mycombo">
<option> Select year</option>
</select>
</form>
</body>
Message was edited by:
skp71
Message was edited by:
skp71
skp71a at 2007-7-12 10:42:04 >
