kj2398
07-25-2003, 11:41 AM
I'm new to javascript and I'm writing a javascript function to grab the current month field from a form, add then add 1 to it. I was able to do this okay and subtract one from the current month. Heres the subtract code that works okay,
var cm = document.forms(0).elements.targetmonth.value;
var cy = document.forms(0).elements.targetyear.value;
cm = cm - 1;
if (cm == 0)
{
cm = 12
cy = cy - 1
}
else
{
}
so if the current month = 3, then this makes current month 2.
The add code:
alert("currmonth = " + document.forms(0).elements.targetmonth.value);
alert("curryear = " + document.forms(0).elements.targetyear.value);
var cm = document.forms(0).elements.targetmonth.value;
var cy = document.forms(0).elements.targetyear.value;
cm = cm + 1;
alert(cm);
if (cm == 13)
{
cm = 1;
cy = cy + 1;
}
else
{
}
alert("cm = " + cm + " cy = " + cy);
If the current month = 2 then this makes the current
var cm = document.forms(0).elements.targetmonth.value;
var cy = document.forms(0).elements.targetyear.value;
cm = cm - 1;
if (cm == 0)
{
cm = 12
cy = cy - 1
}
else
{
}
so if the current month = 3, then this makes current month 2.
The add code:
alert("currmonth = " + document.forms(0).elements.targetmonth.value);
alert("curryear = " + document.forms(0).elements.targetyear.value);
var cm = document.forms(0).elements.targetmonth.value;
var cy = document.forms(0).elements.targetyear.value;
cm = cm + 1;
alert(cm);
if (cm == 13)
{
cm = 1;
cy = cy + 1;
}
else
{
}
alert("cm = " + cm + " cy = " + cy);
If the current month = 2 then this makes the current