Here i will show how to get the next/previous month with year when we click on the next/previous.For this i will get the current month and current year ,Then when we click on the previous button i will decrease the month to 1 and if year will also decrease one when the month is equal to 0.because if we will not decrease the year when the month index reached 0 ,the previous value of year will be displayed if year is completed
function Previous() { if (current_month == 0) { current_month = 11; current_year = current_year - 1; } else { current_month = current_month - 1; } var month = monthNames[current_month]; $('#testmonth').val=month+','+current_year; }when we click on the next button i will increase the month to 1 and if year will also increase one when the month is equal to 11.because if we will not increase the year when the month index reached 11 ,the previous value of year will be displayed if year is completed
function Next() { if (current_month == 11) { current_month = 0; current_year = current_year + 1; } else { current_month = current_month + 1; } var month = monthNames[current_month]; $('#testmonth').val=month+','+current_year; }
No comments:
Post a Comment