Hi,
I'm having problems with the following JavaScript code. I coded in the comments what's happening:
function fetchMaand() {
var dteBegin, dteEnd, clsDate, monthsAhead;
monthsAhead = $('#dteMaand').val(); // dteMaand's value = -3 for example
clsDate = new Date(); // Current time
clsDate.setMonth(clsDate.getMonth() + monthsAhead); // Here it starts doing weird (date is somewhere in 2015 ??)
clsDate.setDate(1);
dteBegin = formatBIN(clsDate);
clsDate.setDate(30);
dteEind = formatBIN(clsDate);
$.get("jsexec/agenda_array_gebeurtenissen.cfm", {
begindatum : dteBegin,
einddatum : dteEind
} , fillMaandBox);
}
function fillMaandBox(result) {
// Handle data
}
function formatBIN(date) {
return date.getFullYear() + "-" + to2(date.getMonth() + 1) + "-" + to2(date.getDate())
}
function to2(i) {
return ("00" + i).substr(("00" + i).length - 2 , 2);
}
Could you please help me out? This is part of a calendar website from me, and I am trying to make a combobox with the month (dteMaand) and if you make a change to that combo, the first function is called (fetchMaand() )
The code is supposed to do the following:
- A user changes the combobox with a month (current month is selected), and the value of the combobox is the relative index (eg. this month is July, May will be -2)
- The function fetchMaand will be called in the onchange event.
My real question is acutally on this one "Why is the date somewhere in 2015?". Wat am I doing wrong in this code?
Thanks!
Yvan