Bug en Javascript
Correr esta página HTML y cambir la combo al mes de octubre. Fijaros que repite un día, normalmente en la última semana.
Aquí está el código, es corto y simple pero creo que contiene un Bug en el objeto Date.
<html>
<head>
<title>Días de un mes</title>
<script>
var msPerDay = 24*60*60*1000; // Milisegundos en 1 día (=86400000 ms);
function WriteDays()
{
yyyy=document.frm.year.options[document.frm.year.selectedIndex].value;
mm=document.frm.moth.options[document.frm.moth.selectedIndex].value;
var initialDate = new Date(yyyy,mm,1);
var contenido="";
var i=0;
while (mm==initialDate.getMonth())
{
i++;
contenido+= i + "." + initialDate.toString() + "<br>";
initialDate.setTime(initialDate.getTime() + msPerDay);
}
if (document.all)
{
document.all["capa"].innerHTML=contenido;
}
else
{
document.layers["capa"].document.open()
document.layers["capa"].document.write(contenido)
document.layers["capa"].document.close()
}
}
</script>
</head>
<body>
<form name="frm">
<table>
<tr>
<td>Year</td>
<td>
<select name="year" onchange="WriteDays();">
<option value="2002">2002
<option value="2003">2003
<option value="2004">2004
<option value="2005">2005
<option value="2006">2006
<option value="2007">2007
</select>
</td>
</tr>
<tr>
<td>Month</td>
<td>
<select name="moth" onchange="WriteDays();">
<option value="0">January
<option value="1">February
<option value="2">March
<option value="3">April
<option value="4">May
<option value="5">June
<option value="6">July
<option value="7">August
<option value="8">September
<option value="9">October
<option value="10">November
<option value="11">December
</select>
</td>
</tr>
</table>
</form>
<div id="capa" style="position:absolute;left:225px; top:10px;height:10px; width:300px;">
</div>
</body>
</html>
Aquí está el código, es corto y simple pero creo que contiene un Bug en el objeto Date.
<html>
<head>
<title>Días de un mes</title>
<script>
var msPerDay = 24*60*60*1000; // Milisegundos en 1 día (=86400000 ms);
function WriteDays()
{
yyyy=document.frm.year.options[document.frm.year.selectedIndex].value;
mm=document.frm.moth.options[document.frm.moth.selectedIndex].value;
var initialDate = new Date(yyyy,mm,1);
var contenido="";
var i=0;
while (mm==initialDate.getMonth())
{
i++;
contenido+= i + "." + initialDate.toString() + "<br>";
initialDate.setTime(initialDate.getTime() + msPerDay);
}
if (document.all)
{
document.all["capa"].innerHTML=contenido;
}
else
{
document.layers["capa"].document.open()
document.layers["capa"].document.write(contenido)
document.layers["capa"].document.close()
}
}
</script>
</head>
<body>
<form name="frm">
<table>
<tr>
<td>Year</td>
<td>
<select name="year" onchange="WriteDays();">
<option value="2002">2002
<option value="2003">2003
<option value="2004">2004
<option value="2005">2005
<option value="2006">2006
<option value="2007">2007
</select>
</td>
</tr>
<tr>
<td>Month</td>
<td>
<select name="moth" onchange="WriteDays();">
<option value="0">January
<option value="1">February
<option value="2">March
<option value="3">April
<option value="4">May
<option value="5">June
<option value="6">July
<option value="7">August
<option value="8">September
<option value="9">October
<option value="10">November
<option value="11">December
</select>
</td>
</tr>
</table>
</form>
<div id="capa" style="position:absolute;left:225px; top:10px;height:10px; width:300px;">
</div>
</body>
</html>