Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/10/2015, 02:25
lk2_89
 
Fecha de Ingreso: agosto-2007
Mensajes: 71
Antigüedad: 16 años, 9 meses
Puntos: 1
Problemas en calendario

Buenos días!!

Estoy haciendo un calendario en javascript pero tengo un problema que no soy capaz de ver... Cuando consulto algún mes en el que el día uno empieza en domingo (véase marzo o noviembre de este año), me lo pinta como lunes... Estoy harto de darle vueltas al código y no encuentro el error.

¿Alguna idea? Muchas gracias.

Código:
<html>
<head><title>Superejercicio - Calendario</title></head>					
<body>

<center>		
<b>CALENDARIO</b>

<form name="calendario" action="">
<p>AÑO	<input type="text" name="año" id="año"  /></p>
<p>MES	<select name="mes" id="mes" size="1" /></p>
<option value="12">mes</option>
<option value="0">Enero</option>
<option value="1">Febrero</option>
<option value="2">Marzo</option>
<option value="3">Abril</option>	
<option value="4">Mayo</option>
<option value="5">Junio</option>
<option value="6">Julio</option>
<option value="7">Agosto</option>
<option value="8">Septiembre</option>
<option value="9">Octubre</option>
<option value="10">Noviembre</option>
<option value="11">Diciembre</option>
</select>		
<input type="submit" value="Calendario" />
</form>

</center>

<script>
var j; var k;
var año=location.search.split("&")[0].split("=")[1];
var mes=location.search.split("&")[1].split("=")[1];
var fecha=new Date();

fecha.setFullYear(año);
fecha.setMonth(mes);
fecha.setDate(+1);
var dia=fecha.getDay();

document.calendario.año.value=año;
document.calendario.mes.value=mes;
document.write("<br><br><br>");
document.write("<center><table>");
document.write("<tr  bgcolor=red >");
document.write("<th><b>Lunes</b><\/th>");
document.write("<th><b>Martes</b><\/th>");
document.write("<th><b>Miercoles</b><\/th>");
document.write("<th><b>Jueves</b><\/th>");
document.write("<th><b>Viernes</b><\/th>");
document.write("<th><b>Sabado</b><\/th>");
document.write("<th><b>Domingo</b><\/th>");
document.write("<\/tr>");
document.write("<tr>");

for(i=1;i<=7;i++)
{
if(i<dia)
	{
	document.write("<td>  <\/td>");
	}
else 
	{
	document.write("<td><script>document.write(fecha.getDate())<\/script><\/td>");
	fecha.setDate(fecha.getDate()+1);
	}
}
document.write("<\/tr>");

for(k=1;k<=5;k++)
{
document.write("<tr>");
for(j=1;j<=7;j++)
{
	if(mes!=fecha.getMonth())
	{
		document.write("<td>  <\/td>");
	}
	else
	{
		document.write("<td><script>document.write(fecha.getDate())<\/script><\/td>");
		fecha.setDate(fecha.getDate()+1);
	}
}
document.write("<\/tr>");
if(mes!=fecha.getMonth())
{
break;
}}

document.write("<\/table><\/center>");

</script>
</body>
</html>