if i have a textbox with a date in it, i want to change the textbox to show one month later
A:
You'll have to get the text out of the text box, which you can then pass to the Date() constructor:
var d = new Date(text);
Then format the date string:
var str = d.getDate(), d.getMonth() + 1, d.getFullYear()
And set the test box to that value
Scobal
2010-05-17 11:45:58
@Scobal - what about december --> january
ooo
2010-05-17 11:47:32
Hmm, I thought it rolled, but maybe you'll have to explicitly check for that. Or there could be a better way entirely
Scobal
2010-05-17 11:50:02
@Scobal - i dont understand your line how its creating a date, it seems like it will create something like 30, 4, 1002
ooo
2010-05-17 11:52:45
My bad, copy+pasted from one of my apps that does it slightly differently!
Scobal
2010-05-17 13:34:38
+3
A:
// assumes document.form1.textbox1.value is a parseable date
var d = new Date( document.form1.textbox1.value );
d.setMonth( d.getMonth( ) + 1 );
document.form1.textbox1.value = ( d.getMonth( ) + 1 ) + '/' + d.getDate( ) + '/' + d.getFullYear( );
Set month supposed to be range proof, as described here.
Salman A
2010-05-17 12:15:38