Newsgroup: it.comp.lang.javascript
Titolo: info date

ciao
problema
data partenza (3 campi select anno-mese-giorno)
data finale (sempre 3 campi select anno mese giorno)
io seleziono l'anno il mese e il giorno dalle prime 3 select
es. 2007 12 24
e dovrei ottenere in automatico che alla suddetta data vengano sommati 
15 giorni ottenendo cosi' nelle 3 select successive la data calcolata
e quindi
2008 01 8
ho provato smanettando con document.form.nomecampo.value e impostando 
una function richiamata sull'evento onBlur lasciando l'ultimo campo 
select della prima data per ottenere il tutto ma ho fatto solo casini...
grazie!

 2008 01 8
tempo fa scaricai uno script utile dal sito 
http://www.z555.com/
 . Ora
il sito non rende più disponibile lo script, ma io ne ho una copia. Lo
incollo qui, ma il messaggio diventerà parecchio lungo.
Osserva la funzione date2.setObjDate(firstDate) che puoi modificare per
risolvere il tuo problema.
Ciao
Oreste
----------------------------------------
HTML
---------------------------------------
<html>
<head>
</head>
<body>
<script language="JavaScript" src="datebox.js"></script>
<script language="JavaScript" src="initdatebox.js"></script>
<script>date1.printHTML();</script>
<br /><br /><br />
<script>date2.printHTML();</script>
</body>
</html>
---------------------------------------
----------------------------------------
initdatebox.js
---------------------------------------
var date1 = new dateBox("date1");
var date2 = new dateBox("date2");
date1.makeDateHTML();
date2.makeDateHTML();
function dateSubmit() {
firstDate  = date1.getObjSelectedDate();
secondDate = date2.getObjSelectedDate();
if (firstDate>secondDate) {
date1.setObjDate(secondDate);
date2.setObjDate(firstDate);
}
return false;
}
---------------------------------------
----------------------------------------
datebox.js
---------------------------------------
/*
dateBox.js 2002-01-09
Author(s): Serge Ryabcuck, 
z555.com
, Copyright 2002
z555.com
 grants you a royalty free license to use or modify this
software provided that this copyright notice appears on all copies.
This software is provided "AS IS," without a warranty of any kind.
*/
/* ToDo
 - Masks like dd/mm/yyyy, mm/dd/yyyy, etc.
 - Redraw of the object after change of object style properties.
 - Rewrite some object methods for conforming with initial idea
   and remoe direct HTML objects calls for properties duplicates
*/
window.dbIE  = document.all ? true : false;
   // IE 4+
window.dbDOM = (document.getElementById && ! document.all) ? true :
false; // NS6, Mozilla, other DOM2 compartible browsers
function dateBox(name, month, day, year) {
 
this.name
            = name;
   this.day             = day;
   this.month           = month;
   this.year            = year;
 
this.id
;
   this.version         = "2.0.1 [Date Box; 20020109] ";
   this.type            = "dateBox";
   this.startYear       = 1998;
   this.endYear         = 2008;
   this.height          = 16;
   this.shortMonthWidth = 47;
   this.longMonthWidth  = 87;
   this.dayWidth        = 38;
   this.yearWidth       = 54;
   this.fontFamily      = 'Arial, Verdana, Helvetica, Espy,
Sans-Serif';
   this.fontSize        = '8pt';
   this.dateBoxStyle    = 'long';
   this.shortMonth = [ 'Jan', 'Feb', 'Mar',
                       'Apr', 'May', 'Jun',
                       'Jul', 'Aug', 'Sep',
                       'Oct', 'Nov', 'Dec'
                     ];
   this.longMonth  = [ 'January', 'February', 'March',
                       'April', 'May', 'June',
                       'July', 'August', 'September',
                       'October', 'November', 'December'
                     ];
// Other Properties;
   this.HTMLcontainer;
   this.objForm;
   this.objMonth;
   this.objDay;
   this.objYear;
// Methods
   this.getName            = getName;
   this.setDay             = setDay;
   this.getDay             = getDay;
   this.setMonth           = setMonth;
   this.getMonth           = getMonth;
   this.setYear            = setYear;
   this.getYear            = getYear;
   this.getID              = getID;
   this.setStartYear       = setStartYear;
   this.getStartYear       = getStartYear;
   this.setEndYear         = setEndYear;
   this.getEndYear         = getEndYear;
   this.getDateBoxStyle    = getDateBoxStyle;
   this.setHeight          = setHeight;
   this.getHeight          = getHeight;
   this.setShortMonth      = setShortMonth;
   this.getShortMonth      = getShortMonth;
   this.setLongMonth       = setLongMonth;
   this.getLongMonth       = getLongMonth;
   this.getMonthWidth      = getMonthWidth;
   this.setDayWidth        = setDayWidth;
   this.getDayWidth        = getDayWidth;
   this.setYearWidth       = setYearWidth;
   this.getYearWidth       = getYearWidth;
   this.getMonthName       = getMonthName;
   this.setFontFamily      = setFontFamily;
   this.getFontFamily      = getFontFamily;
   this.setFontSize        = setFontSize;
   this.getFontSize        = getFontSize;
   this.setObjPointers     = setObjPointers;
   this.makeDateHTML       = makeDateHTML;
   this.printHTML          = printHTML;
   this.monthDays          = monthDays;
   this.limitList          = limitList
   this.getObjForm         = getObjForm;
   this.getObjDay          = getObjDay;
   this.getObjMonth        = getObjMonth;
   this.getObjYear         = getObjYear;
   this.getObjSelectedDate = getObjSelectedDate;
   this.setRawDate         = setRawDate;
   this.setObjDate         = setObjDate;
//Events
   this.onSelectDate       = onSelectDate;
   var curDate = new Date();
   if (!month) { this.month = curDate.getMonth()+1 };
   if (!day)   { this.day   = curDate.getDate() };
   if (!year)  {
       if (window.dbDOM) {
           this.year  = curDate.getYear()+1900;
        } else {
           this.year  = curDate.getYear();
        }
   };
   if (!window.dateBoxes) window.dateBoxes = new Array();
 
this.id
=window.dateBoxes.length;
   window.dateBoxes[window.dateBoxes.length] = this;
}
/////////////////////////////////////////////////////////////
// dateBox.getName()
function getName() {
   return 
this.name
;
}
/////////////////////////////////////////////////////////////
// dateBox.setDay()
function setDay(day) {
   this.day=day;
}
/////////////////////////////////////////////////////////////
// dateBox.getDay()
function getDay() {
   return this.day;
}
/////////////////////////////////////////////////////////////
// dateBox.setMonth()
function setMonth(month) {
   this.month = month;
}
/////////////////////////////////////////////////////////////
// dateBox.getMonth()
function getMonth() {
   return this.month;
}
/////////////////////////////////////////////////////////////
// dateBox.setYear()
function setYear(year) {
   this.year=year;
}
/////////////////////////////////////////////////////////////
// dateBox.getYear()
function getYear() {
   return this.year;
}
/////////////////////////////////////////////////////////////
// dateBox.getID()
function getID() {
   return 
this.id
;
}
/////////////////////////////////////////////////////////////
// dateBox.setStartYear()
function setStartYear(year) {
   this.startYear = year;
}
/////////////////////////////////////////////////////////////
// dateBox.getStartYear()
function getStartYear() {
   return this.startYear;
}
/////////////////////////////////////////////////////////////
// dateBox.setEndYear()
function setEndYear(year) {
   this.endYear = year;
}
/////////////////////////////////////////////////////////////
// dateBox.getEndYear()
function getEndYear() {
   return this.endYear;
}
/////////////////////////////////////////////////////////////
// dateBox.getDateBoxStyle()
function getDateBoxStyle() {
   return this.dateBoxStyle;
}
/////////////////////////////////////////////////////////////
// dateBox.setShortMonth()
function setShortMonth(monthArray) {
   this.shortMonth=monthArray;
}
/////////////////////////////////////////////////////////////
// dateBox.getShortMonth()
function getShortMonth(monthIndex) {
   return this.shortMonth[monthIndex-1];
}
/////////////////////////////////////////////////////////////
// dateBox.setLongMonth()
function setLongMonth(monthArray) {
   this.longMonth=monthArray;
}
/////////////////////////////////////////////////////////////
// dateBox.getLongMonth()
function getLongMonth(monthIndex) {
   return this.longMonth[monthIndex-1];
}
/////////////////////////////////////////////////////////////
// dateBox.getMonthName()
function getMonthName(monthIndex) {
   if (this.getDateBoxStyle() == 'short') {
      return this.getShortMonth(monthIndex);
   } else {
      return this.getLongMonth(monthIndex);
   }
}
/////////////////////////////////////////////////////////////
// dateBox.setHeight()
function setHeight(height) {
   this.height = height;
}
/////////////////////////////////////////////////////////////
// dateBox.getHeight()
function getHeight() {
   return this.height;
}
/////////////////////////////////////////////////////////////
// dateBox.setShortMonthWidth()
function setShortMonthWidth(width) {
   this.shortMonthWidth = width;
}
/////////////////////////////////////////////////////////////
// dateBox.setLongMonthWidth()
function setLongMonthWidth(width) {
   this.longMonthWidth = width;
}
/////////////////////////////////////////////////////////////
// dateBox.getMonthWidth()
function getMonthWidth() {
   if (this.getDateBoxStyle() == 'short') {
      return this.shortMonthWidth;
   } else {
      return this.longMonthWidth;
   }
}
/////////////////////////////////////////////////////////////
// dateBox.setDayWidth()
function setDayWidth(width) {
   this.dayWidth = width;
}
/////////////////////////////////////////////////////////////
// dateBox.getDayWidth()
function getDayWidth() {
   return this.dayWidth;
}
/////////////////////////////////////////////////////////////
// dateBox.setYearWidth()
function setYearWidth(width) {
   this.yearWidth = width;
}
/////////////////////////////////////////////////////////////
// dateBox.getYearWidth()
function getYearWidth() {
   return this.yearWidth;
}
/////////////////////////////////////////////////////////////
// dateBox.setFontFamily()
function setFontFamily(family) {
   this.fontFamily=family;
}
/////////////////////////////////////////////////////////////
// dateBox.getFontFamily()
function getFontFamily() {
   return this.fontFamily;
}
/////////////////////////////////////////////////////////////
// dateBox.setFontSize()
function setFontSize(size) {
   this.fontSize=size;
}
/////////////////////////////////////////////////////////////
// dateBox.getFontSize()
function getFontSize() {
   return this.fontSize;
}
/////////////////////////////////////////////////////////////
// dateBox.getObjForm()
function getObjForm() {
   return this.objForm;
}
/////////////////////////////////////////////////////////////
// dateBox.getObjDay()
function getObjDay() {
   return this.objDay;
}
/////////////////////////////////////////////////////////////
// dateBox.getObjMonth()
function getObjMonth() {
   return this.objMonth;
}
/////////////////////////////////////////////////////////////
// dateBox.getObjYear()
function getObjYear() {
   return this.objYear;
}
/////////////////////////////////////////////////////////////
// dateBox.makeDateHTML()
function makeDateHTML() {
   var dateStr = "";
   // Build Month
   dateStr += '<select name="' + this.getName() + 'Month' +
              '" style="font-family : ' + this.getFontFamily() +
              '; HEIGHT: ' + this.getHeight() + 'px; WIDTH:' +
              this.getMonthWidth() + 'px; font-size: ' +
this.getFontSize() +
              ';" onChange="window.dateBoxes[' + this.getID() +
'].onSelectDate()">';
   for (i=1; i<=12;i++) {
       if (this.getMonth() == i) {
          dateStr += '<option selected value=' + i + '>' +
this.getMonthName(i);
       } else {
          dateStr += '<option value=' + i + '>' + this.getMonthName(i);
       }
   }
   dateStr += "</select>";
   // Build Day
   dateStr += '<select name="' + this.getName() + 'Day' +
              '" style="font-family : ' + this.getFontFamily() +
              '; HEIGHT: ' + this.getHeight() + 'px; WIDTH: ' +
              this.getDayWidth() + 'px; font-size: ' +
this.getFontSize() +
              ';"  onChange="window.dateBoxes[' + this.getID() +
              '].onSelectDate()">';
   for (i=1; i<=31; i++) {
       if (this.getDay() == i) {
           dateStr += '<option selected>'+i;
       } else {
         dateStr += '<option>'+i;
       }
   }
   dateStr += "</select>";
   // Build Year
   dateStr += '<select name="' + this.getName() + 'Year' +
              '" style="font-family : ' + this.getFontFamily() + ';
HEIGHT: ' +
              this.getHeight() + 'px; WIDTH: ' + this.getYearWidth() +
              'px; font-size: ' + this.getFontSize() +
              ';" onChange="window.dateBoxes[' + this.getID() +
'].onSelectDate()">';
   for (i=this.getStartYear(); i<=this.getEndYear(); i++) {
        if (this.getYear() == i) {
           dateStr += '<option selected>' + i;
        } else {
           dateStr += '<option>' + i;
        }
   }
   dateStr += "</select>";
   this.HTMLcontainer=dateStr;
}
/////////////////////////////////////////////////////////////
// dateBox.printHTML()
function printHTML() {
   document.write(this.HTMLcontainer);
   this.setObjPointers(document.forms[document.forms.length-1]);
   this.limitList(this.monthDays(this.getMonth(),this.getYear()));
}
/////////////////////////////////////////////////////////////
// dateBox.setObjPointers()
function setObjPointers(form) {
   this.objForm  = form;
   this.objDay   = eval("form."+this.getName()+"Day");
   this.objMonth = eval("form."+this.getName()+"Month");
   this.objYear  = eval("form."+this.getName()+"Year");
}
// How many days in the month?
/////////////////////////////////////////////////////////////
// dateBox.monthDays()
function monthDays(month,year) {
   var day = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
   month--;
   if ((year % 4 == 0) && (month==1)) {
       if (year % 100 == 0) {
          if (year % 400 == 0) {
              return 29;
          } else {
              return 28;
          }
       } else {
          return 29;
       }
  } else {
     return day[month];
  }
}
// Event processor
/////////////////////////////////////////////////////////////
// dateBox.onSelectDate()
function onSelectDate() {
   if (window.dbIE || window.dbDOM) {
      var objDay=this.getObjDay();
      var objYear=this.getObjYear();
      var objMonth=this.getObjMonth();
      yearVal=objYear.options[objYear.selectedIndex].text;
      monthVal=objMonth.options[objMonth.selectedIndex].value;
      this.limitList(this.monthDays(monthVal,yearVal));
      this.setDay(objDay.selectedIndex+1);
      this.setMonth(objMonth.selectedIndex+1);
      this.setYear(objYear.selectedIndex+this.startYear);
   }
}
//Rebuilds dropdown list of day options according to the month
/////////////////////////////////////////////////////////////
// dateBox.limitList()
function limitList(length) {
   list=this.getObjDay();
   if (length<(list.selectedIndex+1)) {
      list.selectedIndex=length-1;
   }
   if (window.dbIE || window.dbDOM) {
      if (list.options.length<length) {
         for (var i=list.options.length+1; i<=length; i++) {
             var oOption = document.createElement('OPTION');
             if (window.dbIE) {
                list.options.add(oOption);
                oOption.innerText = i;
                oOption.Value = i;
             } else if (window.dbDOM) {
                oOption.text = ' '+i;
                oOption.Value = i;
                list.add(oOption,null);
             }
          }
      } else if (list.options.length>length) {
         for (var i=list.options.length; i>=length; i--) {
             list.remove(i);
         }
      }
  }
}
// Convert form fields to Date object
/////////////////////////////////////////////////////////////
// dateBox.getObjSelectedDate()
function getObjSelectedDate() {
   if (window.dbIE || window.dbDOM) {
      var objDay=this.getObjDay();
      var objYear=this.getObjYear();
      var objMonth=this.getObjMonth();
      var day=objDay.options[objDay.selectedIndex].text;
      var month=objMonth.options[objMonth.selectedIndex].value-1;
      var year=objYear.options[objYear.selectedIndex].text;
      var dateObj = new Date(year, month, day);
      return dateObj;
   }
}
// Set specified Date
/////////////////////////////////////////////////////////////
// dateBox.setRawDate()
function setRawDate(month,day,year) {
   if (window.dbIE || window.dbDOM) {
      var objDay=this.getObjDay();
      var objYear=this.getObjYear();
      var objMonth=this.getObjMonth();
      this.limitList(this.monthDays(month,year));
      objDay.selectedIndex=day-1;
      objMonth.selectedIndex=month-1;
      objYear.selectedIndex=year-this.startYear;
   }
}
/////////////////////////////////////////////////////////////
// dateBox.setObjDate()
function setObjDate(date){
   if (window.dbIE || window.dbDOM) {
       var month = date.getMonth()+1;
       var day   = date.getDate();
       if (window.dbDOM) {
          var year  = date.getYear()+1900;
       } else {
          var year  = date.getYear();
       }
       this.setRawDate(month,day,year);
   }
}
---------------------------------------

 15 giorni ottenendo cosi' nelle 3 select successive la data calcolata
be', puoi prendere i tre valori (dd/mm/aaaa) e costruire la seconda data
con un semplice Date(aaaa, mm, dd+15). dovrebbe funzionare.
Ciao.
Giovanni