Prob in populating the current date in drop down
I want to get the current date into a drop down list.
There are three drop down.
1.Month 2. Day 3. Year.
If anytime the page loads there should be current date in the drop down list. and if any one wants to change he can change the date accordingly.
Can any one help me in sorting out this prob.
I can think of getting the current date in the drop down by keeping it in the 1st option of the select tag. But when you click on the list the current date is not at proper location compared to other numbers in the list.
Please reply.
Message was edited by:
aniketh_parmar
# 1
function addit(){
var dd = new Date();
var yearnow = dd.getFullYear(); //gets 4 digit year
//use getDate() & getMonth() methods in seperate fns, and populate
//date and months
for (var i=yearnow; i <= yearnow + 25 ;++i){
addOption(document.getElementById("year"), 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="month">
</select>
<select name="day">
</select>
<select name="year">
</select>
Have a seperate fn, and using the above 3 methods get
today's (current) month, day & year.
then something like,
document.getElementById("year").selectedIndex = currYear;
document.getElementById("month").selectedIndex = currMonth; //0 is Jan and 11 is Dec
document.getElementById("day").selectedIndex = currDate;