4 Gru 2008

Zwiększenie lub zmieniszenie daty o 1 dzień

function next_day(f, step) {

var data = f.value;
var tab = data.split("-");

var year = tab[0];
var month = tab[1];
var day = tab[2];
var date = new Date(year, month-1, day);

var now = date;
now.setDate(now.getDate() + step);
var year=now.getFullYear();
var month=now.getMonth()+1;
var day=now.getDate();

month = "0" + month;
month = month.substring(month.length-2, month.length);

day = "0" + day;
day = day.substring(day.length-2, day.length);

return year+"-"+month+"-"+day;
}

uruchomienie

var f2 = forma.elements["departure_date"];
var f1 = forma.elements["arrival_date"];

f1.value = next_day(f1, 1);
f2.value = next_day(f2, 1);

f1.value = next_day(f1, -1);
f2.value = next_day(f2, -1);