Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/12/2010, 09:03
Avatar de kaninox
kaninox
 
Fecha de Ingreso: septiembre-2005
Ubicación: In my House
Mensajes: 3.597
Antigüedad: 18 años, 7 meses
Puntos: 49
consulta calendario

Hola masters
Tengo un script en el cual muestro un calendario al hacer click en un boton.
el problema es que necesito crear otro input asociado al calendario y que al hacer click me muestre en su ID, me refiero al input la fecha seleccionada.
solo me resulta con uno el segundo ya no me corre? alguna idea?

la llamada la hago de la siguiente forma :

Código HTML:
Ver original
  1. <input type="text" id='date_input'/><input type ="button" value="..." onClick="calendar_load('date_input',$F('date_input'));"/>

entonces mi idea es agregar otro input de forma
Código HTML:
Ver original
  1. <input type="text" id='date_input2'/><input type ="button" value="..." onClick="calendar_load('date_input2',$F('date_input2'));"/>

en mi funcion function calendar_load no se como agregar el date_input2 ?

Código Javascript:
Ver original
  1. function calendar_load(date_input,value)
  2. {
  3.     //days of the week
  4.     var header= new Array();
  5.     header[1]='Dom';
  6.     header[2]='Lun';
  7.     header[3]='Mar';
  8.     header[4]='Mie';
  9.     header[5]='Jue';
  10.     header[6]='Vie';
  11.     header[7]='Sáb';
  12.     //var meses = new Array ("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
  13.     var dateFormat='d/m/y'; // d/m/y
  14.    
  15.     $('wrapper_calendario').style.visibility='visible';
  16.     var date = new Date(value);
  17.     if(dateFormat=='d/m/y')
  18.     {
  19.         var vals=value.split('/');
  20.         date.setDate(vals[0]);
  21.         date.setMonth(vals[1]-1);
  22.         date.setYear(vals[2]);
  23.     }
  24.     var day =date.getDate();
  25.     var month=date.getMonth()+1;
  26.     var year=date.getFullYear();
  27.     if(!checkdate (month, day, year))
  28.     {
  29.         date = new Date();
  30.         day =date.getDate();
  31.         month=date.getMonth()+1;
  32.         year=date.getFullYear();
  33.     }
  34.     var table = new Element('table',{
  35.     id:date_input+'_table',
  36.     cellspacing:'0'                                        
  37.     });
  38.    
  39.     var thead= new Element('thead');
  40.    
  41.     var tr = new Element('tr');
  42.     for (k=1;k<8;k++)
  43.     {
  44.         var th = new Element('th');
  45.         th.update(header[k]);
  46.         tr.insert(th);
  47.     }
  48.     thead.insert(tr);
  49.     table.insert(thead);
  50.    
  51.     var today=new Date();
  52.    
  53.     var days=daysInMonth(month,year);
  54.    
  55.     wdate=date;
  56.     wdate.setDate(1);
  57.    
  58.     var week=date.getDay();
  59.     var tr= new Element('tr');
  60.     if (week>=1)
  61.     {  
  62.         var td= new Element('td',{'colspan':week,'class':'padding'});
  63.         tr.insert(td);
  64.     }  
  65.     for (n=1;n<=days;n++)
  66.     {
  67.         week++;
  68.         if (week==8)
  69.         {
  70.             table.insert(tr);
  71.            
  72.             tr= new Element('tr');
  73.             week=1;
  74.         }
  75.         var nclass="";
  76.         if (today.getDate()==n && (today.getMonth()+1)==month && (today.getFullYear())==year )
  77.         {nclass="today";}  
  78.        
  79.         var savedate=month+"/"+n+"/"+year;
  80.        
  81.         td =new Element('td',{'class':nclass,
  82.                               onClick: "changeDate('"+date_input+"','"+ savedate +"');"});
  83.         td.update(n);
  84.         tr.insert(td);
  85.        
  86.     }
  87.     if (week<7)
  88.     {
  89.         td= new Element('td',{colspan:(7-week),'class':'padding'});
  90.         tr.insert(td);
  91.     }
  92.     table.insert(tr);
  93.     var div= new Element('div',{id:date_input+'_controls',align:'center',style:'position:relative;'});
  94.    
  95.     var previous= calculate_month(month,year,'previous',dateFormat);
  96.    
  97.     var href= new Element('a',{ href:"javascript:void(0);",onClick:"calendar_load('"+date_input+"','"+previous+"');"})
  98.     href.update('<< ');
  99.     div.insert(href);
  100.     var span= new Element('span');
  101.     span.update(month+' / '+year);
  102.     div.insert(span);
  103.    
  104.     var next= calculate_month(month,year,'next',dateFormat);
  105.    
  106.     var href= new Element('a',{ href:"javascript:void(0);",onClick:"calendar_load('"+date_input+"','"+next+"');"})
  107.     href.update(' >>');
  108.     div.insert(href);
  109.    
  110.     $(date_input+'_calendar').innerHTML='';
  111.     $(date_input+'_calendar').insert(div);
  112.    
  113.     var divtable= new Element('div',{align:'center'});
  114.     divtable.insert(table)
  115.    
  116.     $(date_input+'_calendar').insert(divtable);
  117.     $(date_input+'_calendar').innerHTML='<input type="hidden" id=\''+date_input+'_format\' value=\''+dateFormat+'\'/>'+$(date_input+'_calendar').innerHTML;
  118.     return false;
  119. }
  120.  
  121.  
  122. function calculate_month(actualMonth,actualYear,operation,dateFormat)
  123. {
  124.     if (operation=='next')
  125.     {
  126.         actualMonth++;
  127.         if (actualMonth==13)
  128.         {
  129.             actualMonth=1;
  130.             actualYear++;
  131.         }  
  132.    
  133.     }
  134.     else //  previous
  135.     {
  136.         actualMonth--;
  137.         if (actualMonth==0)
  138.         {
  139.             actualMonth=12;
  140.             actualYear--;
  141.         }  
  142.        
  143.     }  
  144.    
  145.     var date;
  146.     if (dateFormat=='d/m/y')
  147.     {date='1/'+actualMonth+'/'+actualYear;}
  148.     else
  149.     {date=actualMonth+'/1/'+actualYear;}   
  150.     return date;
  151. }
  152.  
  153. function checkdate (month, day, year) {
  154.     var myDate = new Date();
  155.     myDate.setFullYear( year,(month-1),day );
  156.     var ret=month >= 1 && month <= 12 && year >= 1 && year <= 3000 && ((myDate.getMonth()+1) == month && day<32);
  157.     return ret;
  158. }
  159.  
  160. function changeDate(element,originalDate)
  161. {
  162.     var date = new Date(originalDate);
  163.     var day =date.getDate();
  164.     var month=date.getMonth()+1;
  165.     var year=date.getFullYear();
  166.    
  167.    
  168.     if ($F(element+'_format')=='d/m/y')
  169.     {
  170.         $(element).value=day+'/'+month+'/'+year;
  171.     }
  172.     else
  173.     {
  174.         $(element).value=month+'/'+day+'/'+year;
  175.     }
  176.    
  177.     $(element+'_calendar').innerHTML="";
  178.     $('wrapper_calendario').style.visibility='hidden';
  179.     return false;
  180. }
  181. function daysInMonth(month,year){
  182.     days=[0,31,29,31,30,31,30,31,31,30,31,30,31];
  183.     last=0;
  184.     if (month==2)
  185.     {
  186.         date=new Date(year,1,29)
  187.         seeMonth=date.getMonth();
  188.         if((seeMonth+1)!=month){last=28}
  189.     }
  190.     else
  191.     {
  192.         last=days[month]
  193.     }
  194.     return last;
  195. }

lo otro si se fijan al comeinzo tengo comentado un array de meses? se supone que haciendo luego meses[month] me deberia funcionar pero me da un undefined? a que puede deberse esto? la idea es poner nombre del mes arriba y no el numero.

El calendario usado es el de esta web :http://www.codigogratis.com.ar/-post...prototype.html
Demo : http://codigogratis.com.ar/xx/calendar/

Saludos
__________________
Gokuh Salvo al mundo. PUNTO!!!!