codice:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script language="javascript" type="text/javascript">
// <!CDATA[
/*'--------------------------------------------------------------------------
'Restituisce vero o falso a seconda che l'anno passato come argomento
'sia bisestile
'--------------------------------------------------------------------------*/
function IsLeapYear(aYear)
{
if ((aYear % 4 == 0 && aYear % 100 != 0) || (aYear % 400 == 0) )
return true;
else
return false;
}
/*'-----------------------------------------------------------------------
'Restituisce il numero di giorni del mese. Ha come argomenti Anno e mese
'-----------------------------------------------------------------------*/
function DaysInMonth(aYear, aMonth)
{
aYear = parseInt(aYear, 10);
aMonth = parseInt(aMonth, 10);
switch (aMonth)
{
case 4:
case 6:
case 9:
case 11:
return 30;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
case 2:
if(IsLeapYear(aYear)) return 29; else return 28;
}
}
/*---------------------------------------------------------------
Aggiunge un elemento ad una listbox
---------------------------------------------------------------*/
function lista_push(lista, testo, valore)
{
lista.options[lista.options.length] = new Option(testo, valore);
}
/*---------------------------------------------------------------
Cancella tutti gli elementi di una listbox
---------------------------------------------------------------*/
function lista_cancella(lista)
{
var v1 = lista.options;
for (var i = v1.length - 1; i >= 0; i--) lista.remove(i);
}
window.onload = function()
{
var sa = document.getElementById("Select_anno");
lista_push(sa, "", "");
for(var anno = 1900; anno <= 2100; anno++)
lista_push(sa, anno, anno);
sa.onchange = function(){popola_giorni(sa.value, sm.value)};
var sm = document.getElementById("Select_mese");
lista_push(sm, "", "");
for(var mese = 1; mese <= 12; mese++)
lista_push(sm, mese, mese);
sm.onchange = function(){popola_giorni(sa.value, sm.value)};
};
function popola_giorni(anno, mese)
{
var sg = document.getElementById("Select_giorni");
lista_cancella(sg);
if(anno == "" || mese == "") return;
lista_push(sg, "", "");
for(var i = 1; i <= DaysInMonth(anno, mese); i++)
lista_push(sg, i, i);
}
// ]]>
</script>
</head>
<body>
<select id="Select_anno" ></select>
<select id="Select_mese" ></select>
<select id="Select_giorni" ></select>
</body>
</html>