Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery how to increment date

I have two input fields, one with a start date and one with the finish date. How can i automaticaly setup the finish date as start date + 1 day when i input a date in the first field?
My code is like this:

<form>
Start: <input type="text" name="date_start" id="datepicker0">
Stop: <input type="text" name="date_stop" id="datepicker1">
</form>
like image 292
Mike Avatar asked Oct 23 '11 19:10

Mike


1 Answers

Demo - http://jsfiddle.net/ffwr2/1/

$('#date1').datepicker();
$('#date2').datepicker();

$('#date1').change(function(){
    var date1 = $('#date1').datepicker('getDate');
    var date = new Date( Date.parse( date1 ) ); 
    date.setDate( date.getDate() + 1 );

    var newDate = date.toDateString(); 
    newDate = new Date( Date.parse( newDate ) );

    $('#date2').datepicker('setDate', newDate );
})
like image 54
Jayendra Avatar answered Oct 18 '22 13:10

Jayendra