I am trying to display last 3 months of present month (including this total four months) using javascript in drop down
function writeMonthOptions() {
var months = new Array("01", "02", "03", "04", "05", "06", "07", "08",
"09", "10", "11", "12");
var today = new Date();
var date = new Date(today);
date.setFullYear(date.getFullYear() - 1);
var dropDown = document.getElementById("Month_list");
var i = today.getMonth();
var optionNames;
var optionValues;
var beanData = '<s:property value="month" />';
while (i < (today.getMonth() + 4)) {
optionNames = months[i];
optionValues = today.getFullYear() + '' + months[i];
dropDown.options[i++] = new Option(optionNames, optionValues);
if (beanData) {
if (beanData == (today.getFullYear() + "" + monthsInd[today
.getMonth()])) {
dropDown.selectedIndex = i - 1;
}
}
}
}
in simple, show drop down of present month and previous 3 months in the view part. to back-end it needs to be submitted as [YYYYMM].
if already value present in bean, show it as selected in drop down. [guaranteed that it will be in those 4 months]