Foros del Web » Programando para Internet » Javascript »

Modificar script calendario

Estas en el tema de Modificar script calendario en el foro de Javascript en Foros del Web. Hola a todos, encontré por una web este script de un calendario y necesitaría saber como modificarlo para resaltar los días que yo le diga. ...
  #1 (permalink)  
Antiguo 15/06/2010, 00:43
 
Fecha de Ingreso: junio-2010
Mensajes: 2
Antigüedad: 13 años, 10 meses
Puntos: 0
Modificar script calendario

Hola a todos, encontré por una web este script de un calendario y necesitaría saber como modificarlo para resaltar los días que yo le diga. Ahora sólo resalta el día en el que estamos.
<SCRIPT LANGUAGE="JavaScript">

<!-- Hide

// define variables

var month_names = new Array("Ene","Feb","Mar","Abr","May","Jun","Jul","A go","Sep","Oct","Nov","Dic");
var days_in_month = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var this_date = new Date(); // get todays date
var this_day = this_date.getDate(); // returns date within month - range 1-31
var this_month = this_date.getMonth(); // returns month within year - range 0-11

function makeCalendar(the_month, the_year)
{ first_of_month = new Date(the_year, the_month, 1); // creates instance of date object for first of month
day_of_week = first_of_month.getDay()-1; // returns day within week - range 0-6
if (((the_year % 4 == 0) && (the_year % 100 != 0)) || (the_year % 400 == 0))
{ days_in_month[1] = 29; // it's a leap year so change # days in Feb in array
}
else
{ days_in_month[1] = 28; // not leap year - future use if multi year calendar built
}
document.write("<TABLE CALLSPACING=0 CELLPADDING=0>"); // start building the month table
document.write("<TR BGCOLOR='#FFCC99'><TH COLSPAN=7>" + month_names[the_month] + " " + the_year); // month and year heading
document.write("<TR BGCOLOR='#FF8888'><TH>L</TH><TH>M</TH><TH>M</TH><TH>J</TH><TH>V</TH><TH>S</TH><TH>D</TH></TR>"); // day of week heading
document.write("<TR ALIGN=RIGHT>");
var column = 0;
for (i=0; i<day_of_week; i++) // skip to day_of_week value for first_of_month
{ document.write("<TD> </TD>");
column++;
}
for (i=1; i<=days_in_month[the_month]; i++)
{ if ((i == this_day) && (the_month == this_month) && (the_year == this_year))
{ document.write("<TD BGCOLOR='#CC0000'><B>" + i + "</B></TD>"); // highlite todays date
}
else
{ document.write("<TD BGCOLOR='#33CCFF'><B>" + i + "</B></TD>"); // no highlite for other dates
}
column++;
if (column == 7) // start next row of dates for month
{ document.write("</TR><TR ALIGN=RIGHT>");
column = 0;
}
}
document.write("</TR></TABLE>"); // month complete - close table
}

function y2K(number) // if year < 2000 javascript gives only 2 digits for year
{ return (number < 1000) ? number + 1900 : number;
}

var this_year = y2K(this_date.getYear());
// -->

</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">

<!--

document.write("<TABLE BORDER='1'><TR VALIGN=TOP><TD>");
//makeCalendar(0, this_year); // we are passing the month and year to build the calendar
//document.write("</TD><TD>"); // in JavaScipt the first month is 0
//makeCalendar(1, this_year);
//document.write("</TD><TD>");
//makeCalendar(2, this_year);
//document.write("</TD><TD>");
//makeCalendar(3, this_year);
//document.write("</TD></TR><TR VALIGN=TOP><TD>");
//makeCalendar(4, this_year);
//document.write("</TD><TD>");
makeCalendar(5, this_year);
document.write("</TD><TD>");
makeCalendar(6, this_year);
document.write("</TD><TD>");
makeCalendar(7, this_year);
document.write("</TD><TD>");
makeCalendar(8, this_year);
document.write("</TD><TD>");
makeCalendar(9, this_year);
document.write("</TD><TD>");
makeCalendar(10, this_year);
document.write("</TD></TR></TABLE>");
//makeCalendar(11, this_year);
//document.write("</TD></TR></TABLE>");
document.close();

// -->

</SCRIPT>

Ya he modificado algunas líneas del original para que me aparezca 1º el lunes y no el domingo. Sé que en esta parte del código es donde resalta el día de hoy:
for (i=1; i<=days_in_month[the_month]; i++)
{ if ((i == this_day) && (the_month == this_month) && (the_year == this_year))
{ document.write("<TD BGCOLOR='#CC0000'><B>" + i + "</B></TD>"); // highlite todays date
}
else
{ document.write("<TD BGCOLOR='#33CCFF'><B>" + i + "</B></TD>"); // no highlite for other dates
}

¿Habría alguna forma de aparte de resaltar el día de hoy, resaltar las fechas que yo quiera?. Muchas Gracias.
  #2 (permalink)  
Antiguo 15/06/2010, 12:28
 
Fecha de Ingreso: mayo-2010
Mensajes: 84
Antigüedad: 13 años, 11 meses
Puntos: 0
Respuesta: Modificar script calendario

document.write("<TD BGCOLOR='#33CCFF'><B>" + i + "</B></TD>"); // no highlite for other dates, modifica está línea, no lo he probado, pero creo que es esa. De todas formas, para no marearte mucho, prueba y error con los BGCOLOR, que sólo hay varios
__________________
http://www.pcexpansion.es
  #3 (permalink)  
Antiguo 15/06/2010, 15:59
 
Fecha de Ingreso: junio-2010
Mensajes: 2
Antigüedad: 13 años, 10 meses
Puntos: 0
Respuesta: Modificar script calendario

Hola y gracias por contestar.
Al final he conseguido algo anidando la función if:

for (i=1; i<=days_in_month[the_month]; i++)
{ if ((i >= 15) && (the_month == 7) && (the_year == this_year))
{ document.write("<TD BGCOLOR='#CC0000'><B>" + i + "</B></TD>"); // highlite todays date
}
else
if ((i == this_day) && (the_month == this_month) && (the_year == this_year))
{ document.write("<TD BGCOLOR='#CC0000'><B>" + i + "</B></TD>"); // highlite todays date
}
else
{ document.write("<TD BGCOLOR='#33CCFF'><B>" + i + "</B></TD>"); // no highlite for other dates
}

El problema está que resalta del día que le digo hasta el final o hasta el principio de mes. ¿Habría alguna función como la que se utiliza en visual basic ("Entre") para validar entre 2 fechas?.

Última edición por sespir; 15/06/2010 a las 16:17

Etiquetas: calendario, disponibilidad
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:34.