views:

88

answers:

2

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
@Scobal - what about december --> january
ooo
Hmm, I thought it rolled, but maybe you'll have to explicitly check for that. Or there could be a better way entirely
Scobal
@Scobal - i dont understand your line how its creating a date, it seems like it will create something like 30, 4, 1002
ooo
My bad, copy+pasted from one of my apps that does it slightly differently!
Scobal
+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