Autor |
Mensaje |
-
ganardinerofacilporinternet
Junior
Ubicación: Barcelona
|
20-12-2008, 22:02 (UTC) Título del mensaje: [Resuelto] Me gustaria un calendario |
|
|
Pues me gustaria tener algun calendario,si alguien tiene el codigo se lo agradeceria mucho
de dias,mes y año
Muchas gracias
Ultima edición por ganardinerofacilporinternet el Sab Dic 20, 2008 7:20 pm; editado 1 vez
|
|
↑
|
|
|
-
eldirectorioweb
Junior
Ubicación: Alajuela,Costa Rica
|
20-12-2008, 22:08 (UTC) Título del mensaje: |
|
|
aquí hay uno,espero que te sirva:
Código: <SCRIPT LANGUAGE="JavaScript">
<!-- Mas trucos y scripts en http://www.javascript.com.mx -->
<!-- Begin
var now = new Date();
var month_array = new Array("january","february","march","April","May","June","July","August","September","October","November","December");
document.write("<form name=date_list><table bgcolor=silver><tr><td>");
document.write("<select name=month onchange=change_month(this.options.selectedIndex)>");
for(i=0;i<month_array.length;i++)
{
if (now.getMonth() != i)
{document.write ("<option value="+i+">"+month_array[i]);}
else
{document.write ("<option value="+i+" selected>"+month_array[i]);}
}
document.write("</select>");
document.write("</td><td>");
document.write ("<select name=year onchange=change_year(this.options[this.options.selectedIndex])>");
for(i=1950;i<3000;i++)
{
if (now.getYear() != i)
{document.write("<option value="+i+">"+i);}
else
{document.write("<option value="+i+" selected>"+i);}
}
document.write("</select></td></tr><tr><td colspan=2><center>");
document.write("<table bgcolor=white border=0 cellspacing = 0 cellpading = 0 width=100%><tr bgcolor=gray align=center>");
document.write("<td><font color=silver>M</font></td><td><font color=silver>T</td><td><font color=silver>W</td><td><font color=silver>T</td><td><font color=silver>F</td><td ><font color=silver>S</td><td ><font color=silver>S</td>");
document.write("</tr><tr>");
for(j=0;j<6;j++)
{
for(i=0;i<7;i++)
{
document.write("<td align=center id=d"+i+"r"+j+"></td>")
}
document.write("</tr>");
}
document.write("</table>");
document.write("</center></from></td></tr></table>");
var show_date = new Date();
function set_cal(show_date)
{
begin_day = new Date (show_date.getYear(),show_date.getMonth(),1);
begin_day_date = begin_day.getDay();
end_day = new Date (show_date.getYear(),show_date.getMonth()+1,1);
count_day = (end_day - begin_day)/1000/60/60/24;
input_table(begin_day_date,count_day);
}
set_cal(show_date);
function input_table(begin,count)
{
init();
j=0;
if (begin!=0){i=begin-1;}else{i=6}
for (c=1;c<count+1;c++)
{
colum_name = eval("d"+i+"r"+j);
if ((now.getDate() == c)&&(show_date.getMonth() == now.getMonth())&&(show_date.getYear() == now.getYear())) {colum_name.style.backgroundColor = "blue";colum_name.style.color = "white";};
colum_name.innerText = c;
i++;
if (i==7){i=0;j++;}
}
}
function init()
{
for(j=0;j<6;j++)
{
for(i=0;i<7;i++)
{
colum_name = eval("d"+i+"r"+j);
colum_name.innerText = "-";
colum_name.style.backgroundColor ="";
colum_name.style.color ="";
}
}
}
function change_month(sel_month)
{
show_date = new Date(show_date.getYear(),sel_month,1);
set_cal(show_date);
}
function change_year(sel_year)
{
sel_year = sel_year.value;
show_date = new Date(sel_year,show_date.getMonth(),1);
set_cal(show_date);
}
// End -->
</script> |
|
↑
|
|
|
-
ganardinerofacilporinternet
Junior
Ubicación: Barcelona
|
20-12-2008, 22:13 (UTC) Título del mensaje: |
|
|
Me sale como fecha el 1950,cuando lo pongo a 2008,al cargar la web otra vez,se me vuelve a poner al 1950...Que hago?Algun otro? |
|
↑
|
|
|
-
eldirectorioweb
Junior
Ubicación: Alajuela,Costa Rica
|
20-12-2008, 22:22 (UTC) Título del mensaje: |
|
|
voy a buscar otro!!! |
|
↑
|
|
|
-
ganardinerofacilporinternet
Junior
Ubicación: Barcelona
|
20-12-2008, 22:24 (UTC) Título del mensaje: |
|
|
Ok,pues aqui te espero xD |
|
↑
|
|
|
-
ishared
Junior
Ubicación: La Plata/ Buenos Aires/ Argentina
|
20-12-2008, 22:25 (UTC) Título del mensaje: |
|
|
Código: <html>
<body>
<title>calendario javascript basico</title>
<center>este es un simple calendario.</center>
<script type="text/javascript">
function greeting()
{
var today = new date();
var hrs = today.gethours();
document.writeln("<center>");
document.writeln("<br>");
document.write("<h1>buen");
if (hrs < 6)
document.write("as madrugador");
else if (hrs < 12)
document.write(" día");
else if (hrs <= 18)
document.write("as tardes");
else
document.write("as noches");
document.writeln("!</h1>");
document.write("vos ingresaste a esta página el ");
daystr = today.tolocalestring();
document.write(daystr);
document.writeln("</center>");
}
function montharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11)
{
this[0] = m0;
this[1] = m1;
this[2] = m2;
this[3] = m3;
this[4] = m4;
this[5] = m5;
this[6] = m6;
this[7] = m7;
this[8] = m8;
this[9] = m9;
this[10] = m10;
this[11] = m11;
}
function calendar()
{
var monthnames = "enefebmarabrmayjunjulagosepoctnovdic";
var today = new date();
var thisday;
var monthdays = new montharr(31, 28, 31, 30, 31, 30, 31, 31, 30,
31, 30, 31);
year = today.getyear() ;
thisday = today.getdate();
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
monthdays[1] = 29;
ndays = monthdays[today.getmonth()];
firstday = today;
firstday.setdate(1); // works fine for most systems
testme = firstday.getdate();
if (testme == 2)
firstday.setdate(0);
startday = firstday.getday();
document.writeln("<center>");
document.write("<table border>");
document.write("<tr><th colspan=7>");
document.write(monthnames.substring(today.getmonth() * 3,
(today.getmonth() + 1) * 3));
document.write(". ");
document.write(year);
document.write("<tr><th>dom<th>lun<th>mar<th>mie<th>jue<th>vie<th>sab");
document.write("<tr>");
column = 0;
for (i=0; i<startday; i++)
{
document.write("<td>");
column++;
}
for (i=1; i<=ndays; i++)
{
document.write("<td>");
if (i == thisday)
document.write("<font color=\"#ff0000\"><b>")
document.write(i);
if (i == thisday)
document.write("</b></font>")
column++;
if (column == 7)
{
document.write("<tr>");
column = 0;
}
}
document.write("</table>");
document.writeln("</center>");
}
greeting();
document.write("</br>");
calendar();
document.write("");
</script>
<br><br><br>
</body>
</html>
Saludos espero que te sirva. ______________ [Links externos no se admiten en la firma de foro]
Ultima edición por ishared el Sab Dic 20, 2008 6:25 pm; editado 1 vez
|
|
↑
|
|
|
-
ganardinerofacilporinternet
Junior
Ubicación: Barcelona
|
20-12-2008, 22:34 (UTC) Título del mensaje: |
|
|
He copiado el codigo tal y como me lo has dado,pero solo me sale "este es un simple calendario.",no veo el calendario ni nada...Que hago? |
|
↑
|
|
|
-
ishared
Junior
Ubicación: La Plata/ Buenos Aires/ Argentina
|
20-12-2008, 22:40 (UTC) Título del mensaje: |
|
|
Perdon !! Reconozco mi error, aqui te dejo uno nuevo ya probado por mi, es muy bueno:
Código: <html>
<head>
<title>Calendario 4</title>
<p align="center"><b>Calendario 4
</head>
<BODY style="font-family: Verdana">
<script language="JavaScript">
//Form button calendar (author unknown)
//For this script and more
//Visit http://javascriptkit.com
function setDate(str) {
if (str == " ") {
return;
}
mnth1 = document.forms[0].month.value;
mnth = mnth1;
mnth++;
year = document.forms[0].year.value;
dateStr = mnth+"/"+str+"/"+year;
dateStr = trim(dateStr);
document.forms[1].dateField.value = dateStr;
}//setDate()
/**
* The function removes spaces from the selected date.
*/
function trim(str) {
res="";
for(var i=0; i< str.length; i++) {
if (str.charAt(i) != " ") {
res +=str.charAt(i);
}
}
return res;
}//trim()
/**
* The method to get the Month name given the Month number of the year.
*/
function getMonthName(mnth) {
if (mnth == 0) {
name = "Enero";
}else if(mnth==1) {
name = "Febrero";
}else if(mnth==2) {
name = "Marzo";
}else if(mnth==3) {
name = "Abril";
}else if(mnth==4) {
name = "Mayo";
} else if(mnth==5) {
name = "Junio";
} else if(mnth==6) {
name = "Julio";
} else if(mnth==7) {
name = "Agosto";
} else if(mnth==8) {
name = "Septiembre";
} else if(mnth==9) {
name = "Octubre";
} else if(mnth==10) {
name = "Noviembre";
} else if(mnth==11) {
name = "Diciembre";
}
return name;
}//getMonthName()
/**
* Get the number of days in the month based on the year.
*/
function getNoOfDaysInMnth(mnth,yr) {
rem = yr % 4;
if(rem ==0) {
leap = 1;
} else {
leap = 0;
}
noDays=0;
if ( (mnth == 1) || (mnth == 3) || (mnth == 5) ||
(mnth == 7) || (mnth == 8) || (mnth == 10) ||
(mnth == 12)) {
noDays=31;
} else if (mnth == 2) {
noDays=28+leap;
} else {
noDays=30;
}
//alert(noDays);
return noDays;
}//getNoOfDaysInMnth()
/**
* The function to reset the date values in the buttons of the
* slots.
*/
function fillDates(dayOfWeek1,noOfDaysInmnth) {
for(var i=1; i<43; i++) {
str = "s"+i;
document.forms[0].elements[str].value=" ";
}
startSlotIndx = dayOfWeek1;
slotIndx = startSlotIndx;
for(var i=1; i<(noOfDaysInmnth+1); i++) {
slotName = "s"+slotIndx;
val="";
if (i<10) {
val = " "+i+" ";
} else {
val = i;
}
document.forms[0].elements[slotName].value = val;
slotIndx++;
}
}//fillDates()
/**
* The function that is called at the time of loading the page.
* This function displays Today's date and also displays the
* the calendar of the current month.
*/
function thisMonth() {
dt = new Date();
mnth = dt.getMonth(); /* 0-11*/
dayOfMnth = dt.getDate(); /* 1-31*/
dayOfWeek = dt.getDay(); /*0-6*/
yr = dt.getFullYear(); /*4-digit year*/
//alert("month:"+(mnth+1)+":dayofMnth:"+dayOfMnth+":dayofweek:"+dayOfWeek+":year:"+yr);
mnthName = getMonthName(mnth)+ " ";
document.forms[0].month.value = mnth;
document.forms[0].year.value = yr;
document.forms[0].currMonth.value = mnth;
document.forms[0].currYear.value = yr;
document.forms[0].monthYear.value = mnthName+yr;
document.forms[1].dateField.value = (mnth+1)+"/"+dayOfMnth+"/"+yr;
startStr = (mnth+1)+"/1/"+yr;
dt1 = new Date(startStr);
dayOfWeek1 = dt1.getDay(); /*0-6*/
noOfDaysInMnth = getNoOfDaysInMnth(mnth+1,yr);
fillDates(dayOfWeek1+1,noOfDaysInMnth);
}//thisMonth()
/**
* The function that will be used to display the calendar of the next month.
*/
function nextMonth() {
var currMnth = document.forms[0].month.value;
currYr = document.forms[0].year.value;
if (currMnth == "11") {
nextMnth = 0;
nextYr = currYr;
nextYr++;
} else {
nextMnth=currMnth;
nextMnth++;
nextYr = currYr;
}
mnthName = getMonthName(nextMnth);
document.forms[0].month.value=nextMnth;
document.forms[0].year.value=nextYr;
document.forms[0].monthYear.value= mnthName+" "+nextYr;
str = (nextMnth+1)+"/1/"+nextYr;
dt = new Date(str);
dayOfWeek = dt.getDay();
noOfDays = getNoOfDaysInMnth(nextMnth+1,nextYr);
fillDates(dayOfWeek+1,noOfDays);
}//nextMonth()
/**
* The method to display the calendar of the previous month.
*/
function prevMonth() {
var currMnth = document.forms[0].month.value;
currYr = document.forms[0].year.value;
if (currMnth == "0") {
prevMnth = 11;
prevYr = currYr;
prevYr--;
} else {
prevMnth=currMnth;
prevMnth--;
prevYr = currYr;
}
str = (prevMnth+1)+"/1/"+prevYr;
dt = new Date(str);
dayOfWeek = dt.getDay();
/***********************************************
* Remove the comment if do not want the user to
* go to any previous month than this current month.
***********************************************/
/*
runningMonth = document.forms[0].currMonth.value;
rMonth=runningMonth;
rMonth++;
runningYear = document.forms[0].currYear.value;
rYear=runningYear;
str = (rMonth)+"/1/"+rYear;
dt1 = new Date(str);
if (dt.valueOf() < dt1.valueOf()) {
alert('Cannot Go Before Current Month');
return;
}
*/
/**************************************************
* End of comment
**************************************************/
mnthName = getMonthName(prevMnth);
document.forms[0].month.value=prevMnth;
document.forms[0].year.value=prevYr;
document.forms[0].monthYear.value= mnthName+" "+prevYr;
noOfDays = getNoOfDaysInMnth(prevMnth+1,prevYr);
fillDates(dayOfWeek+1,noOfDays);
}//prevMonth()
</script>
</head>
</b>
<body onload="thisMonth()">
</p>
<table border=1 bgcolor="#BAA0A0" align=center>
<tr>
<td>
<form>
<!-- Hidden fields --->
<input type=hidden name=month value="">
<input type=hidden name=year value="">
<input type=hidden name=currMonth value="">
<input type=hidden name=currYear value="">
<!-- End of Hidden fields --->
<p>
<input type="button" name="prev" onclick="prevMonth()"
value="<<">
<input type="text" size="15" name="monthYear"
value="">
<input type="button" name="next" onclick="nextMonth()" value=">>">
</p>
<table bgcolor="#D4D4D4" align=center border="1" cellpadding="0" cellspacing="0"
width="150">
<tr bgcolor="#10A0A0">
<td width="14%"><font size="1"><strong>DOM</strong></font></td>
<td width="14%"><font size="1"><strong>LUN</strong></font></td>
<td width="14%"><font size="1"><strong>MAR</strong></font></td>
<td width="14%"><font size="1"><strong>MIÉ</strong></font></td>
<td width="14%"><font size="1"><strong>JUE</strong></font></td>
<td width="15%"><font size="1"><strong>VIE</strong></font></td>
<td width="15%"><font size="1"><strong>SÁB</strong></font></td>
</tr>
<tr>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s1" value=" 1 "></td>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s2" value=" 2 "></td>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s3" value=" 3 "></td>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s4" value=" 4 "></td>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s5" value=" 5 "></td>
<td align="center" width="15%"><input type="button"
onclick="setDate(this.value);"
name="s6" value=" 6 "></td>
<td align="center" width="15%"><input type="button"
onclick="setDate(this.value);"
name="s7" value=" 7 "></td>
</tr>
<tr>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s8" value=" 8 "></td>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s9" value=" 9 "></td>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s10" value="10"></td>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s11" value="11"></td>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s12" value="12"></td>
<td align="center" width="15%"><input type="button"
onclick="setDate(this.value);"
name="s13" value="13"></td>
<td align="center" width="15%"><input type="button"
onclick="setDate(this.value);"
name="s14" value="14"></td>
</tr>
<tr>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s15" value="15"></td>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s16" value="16"></td>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s17" value="17"></td>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s18" value="18"></td>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s19" value="19"></td>
<td align="center" width="15%"><input type="button"
onclick="setDate(this.value);"
name="s20" value="20"></td>
<td align="center" width="15%"><input type="button"
onclick="setDate(this.value);"
name="s21" value="21"></td>
</tr>
<tr>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s22" value="22"></td>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s23" value="23"></td>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s24" value="24"></td>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s25" value="25"></td>
<td align="center" width="14%"><input type="button"
onclick="setDate(this.value);"
name="s26" value="26"></td>
<td align="center" width="15%"><input type="button"
onclick="setDate(this.value);"
name="s27" value="27"></td>
<td align="center" width="15%"><input type="button"
onclick="setDate(this.value);"
name="s28" value="28"></td>
</tr>
<tr>
<td align="center"><input type="button" name="s29"
onclick="setDate(this.value);"
value="29"></td>
<td align="center"><input type="button" name="s30"
onclick="setDate(this.value);"
value="30"></td>
<td align="center"><input type="button" name="s31"
onclick="setDate(this.value);"
value=" "></td>
<td align="center"><input type="button" name="s32"
onclick="setDate(this.value);"
value=" "></td>
<td align="center"><input type="button" name="s33"
onclick="setDate(this.value);"
value=" "></td>
<td align="center"><input type="button" name="s34"
onclick="setDate(this.value);"
value=" "></td>
<td align="center"><input type="button" name="s35"
onclick="setDate(this.value);"
value=" "></td>
</tr>
<tr>
<td align="center"><input type="button" name="s36"
onclick="setDate(this.value);"
value=" "></td>
<td align="center"><input type="button" name="s37"
onclick="setDate(this.value);"
value=" "></td>
<td align="center"><input type="button" name="s38"
onclick="setDate(this.value);"
value=" "></td>
<td align="center"><input type="button" name="s39"
onclick="setDate(this.value);"
value=" "></td>
<td align="center"><input type="button" name="s40"
onclick="setDate(this.value);"
value=" "></td>
<td align="center"><input type="button" name="s41"
onclick="setDate(this.value);"
value=" "></td>
<td align="center"><input type="button" name="s42"
onclick="setDate(this.value);"
value=" "></td>
</tr>
</table>
</form>
<form>
<table border=0 cellspacing=1 cellpadding=1>
<tr>
<td>
Seleccionado:
</td>
<td align=center>
<input type=text size="12" name=dateField>
</td>
</table>
</form>
</td>
</tr>
</table>
</body>
</html> ______________ [Links externos no se admiten en la firma de foro]
|
|
↑
|
|
|
-
ganardinerofacilporinternet
Junior
Ubicación: Barcelona
|
20-12-2008, 22:57 (UTC) Título del mensaje: |
|
|
Muy bueno!!!
Sabes como hacerlo mas pequeño? |
|
↑
|
|
|
-
ishared
Junior
Ubicación: La Plata/ Buenos Aires/ Argentina
|
20-12-2008, 23:06 (UTC) Título del mensaje: |
|
|
Perdon, pero el codigo no me deja achicarlo mas, pero quedate tranquilo que con el diseño que tienes la plantilla no esta deformada !
Saludos ! ______________ [Links externos no se admiten en la firma de foro] |
|
↑
|
|
|
-
ganardinerofacilporinternet
Junior
Ubicación: Barcelona
|
20-12-2008, 23:15 (UTC) Título del mensaje: |
|
|
Ok,pues muchas gracias |
|
↑
|
|
|
|