Ver Mensaje Individual
  #4 (permalink)  
Antiguo 27/01/2011, 19:37
__SDP__
 
Fecha de Ingreso: agosto-2010
Ubicación: santiago, CHILE
Mensajes: 564
Antigüedad: 14 años, 5 meses
Puntos: 9
Respuesta: Problemas con la funcion en javascrip

ahora si funciona.....

tenias el arreglo toc[0] en vez de cot[0]

xD...

Código PHP:
Ver original
  1. <html>
  2.  
  3.       <head>
  4.  
  5.       <meta http-equiv="Content-Type" content="text/html;charset=UTF-8;" />
  6.  
  7.       <title>Documento sin titulo</title>
  8.  
  9.       </head>
  10.  
  11.        
  12.  
  13.       <script language="javascript" type="text/javascript">
  14.  
  15.        
  16.  
  17.       function Validar(Cadena){  
  18.  
  19.           var fe=Cadena;
  20.  
  21.          
  22.  
  23.           var Dia = parseInt(fe.substr(0,2));
  24.  
  25.           var Mes = parseInt(fe.substr(3,4));
  26.  
  27.           var Ano = parseInt(fe.substr(6,4));
  28.  
  29.          
  30.  
  31.           var mensaje="";
  32.  
  33.           if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900) mensaje= "Año inválido";
  34.  
  35.           if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12) mensaje = "Mes incorrecto";
  36.  
  37.           if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31)mensaje = "Día inválido";  
  38.  
  39.           if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {  
  40.  
  41.               if (Mes==2 && Dia > 28 || Dia>30) {  
  42.  
  43.                   mensaje= "dia invalido";
  44.  
  45.               }  
  46.  
  47.           }  
  48.  
  49.                
  50.  
  51.            if (mensaje!="") {
  52.  
  53.               alert("Atencion, la fecha es incorrecta");
  54.  
  55.               return false;
  56.  
  57.           } else {
  58.  
  59.              
  60.  
  61.               return true;
  62.  
  63.           }
  64.  
  65.        
  66.  
  67.       }  
  68.  
  69.       function validahora(str)
  70.         {
  71.  
  72.           var mensaj=str;
  73.  
  74.           var des="";
  75.  
  76.           var reshor2= mensaj.split(':');
  77.  
  78.          
  79.  
  80.           var hora4= reshor2[0];
  81.  
  82.           var minuto4 = reshor2[1];
  83.  
  84.           var segundo4 = reshor2[2];
  85.  
  86.          
  87.  
  88.           if(hora4 > 24) des="error";
  89.  
  90.           if(minuto4 > 60) des="error";
  91.  
  92.           if(segundo4 > 60) des="error";
  93.  
  94.  
  95.           if (des!="") {
  96.  
  97.               alert("Error en la hora: \n\n introduce la fecha en este tipo HH:MM:SS ");
  98.  
  99.               return false;
  100.  
  101.           } else {
  102.  
  103.              
  104.  
  105.               return true;
  106.  
  107.           }
  108.  
  109.       }
  110.  
  111.       function increaseTime(datehor,time)
  112.        {
  113.  
  114.           var inc = time;
  115.  
  116.           var de = datehor;
  117.  
  118.           var cot = de.split(' ');
  119.  
  120.           var fe = cot[0];
  121.  
  122.           var hor = cot[1];
  123.  
  124.           var incSecond= 0;
  125.  
  126.           var incMinute= 0;
  127.  
  128.           var incHour= 0;
  129.  
  130.           var incDay= 0;
  131.  
  132.           var incMonth= 0;
  133.  
  134.           var incYear= 0;
  135.  
  136.           while (inc >0)
  137.  
  138.           {
  139.  
  140.                   if (inc < 86400)  
  141.  
  142.                   {
  143.  
  144.                       if (inc < 3600)
  145.  
  146.                       {
  147.  
  148.                           if (inc < 60)
  149.  
  150.                           {
  151.  
  152.                               //Segundos
  153.  
  154.                               incSecond=inc;
  155.  
  156.                               inc=inc-incSecond;
  157.  
  158.                           }
  159.  
  160.                           else
  161.  
  162.                           {
  163.  
  164.                               //Minutos
  165.  
  166.                               incMinute=Math.floor(inc/60);
  167.  
  168.                               inc=inc-(incMinute*60);                
  169.  
  170.                           }
  171.  
  172.                       }
  173.  
  174.                       else
  175.  
  176.                       {
  177.  
  178.                           //Horas
  179.  
  180.                           incHour=Math.floor(inc/3600);
  181.  
  182.                           inc=inc-(incHour*3600);
  183.  
  184.                       }
  185.  
  186.                   }
  187.  
  188.                   else
  189.  
  190.                   {
  191.  
  192.                       //Dias
  193.  
  194.                       incDay=Math.floor(inc/86400);
  195.  
  196.                       inc=inc-(incDay*86400);
  197.  
  198.                   }  
  199.  
  200.                   //return resta(incDay,incHour,incMinute);
  201.  
  202.                  
  203.  
  204.           }
  205.  
  206.          
  207.  
  208.           //descomponer las fechas en dia mes y año
  209.  
  210.           //var fe=document.getElementById("fecha").value;
  211.  
  212.           var esvalido=Validar(fe);
  213.  
  214.           if (esvalido==false)
  215.  
  216.           {
  217.  
  218.               return;
  219.  
  220.           }
  221.  
  222.          
  223.  
  224.           var day = parseInt(fe.substr(0,2));
  225.  
  226.           var month = parseInt(fe.substr(3,4));
  227.  
  228.           var year = parseInt(fe.substr(6,4));
  229.  
  230.           //comprobar las restas de las los dias meses y años
  231.  
  232.           if(incDay > 0 ){
  233.  
  234.               day=day-1;
  235.  
  236.           }
  237.  
  238.           if(day < 1 ){
  239.  
  240.           month=month-1;
  241.  
  242.           }
  243.  
  244.           if (month <1){
  245.  
  246.               year=year-1;
  247.  
  248.           }
  249.  
  250.           if (month==0){
  251.  
  252.                month=12;        
  253.  
  254.           }
  255.  
  256.          
  257.  
  258.           //asignando las variables de los dias del año
  259.  
  260.           var ene=31; var feb=28; var feb2=29; var mar=31; var abr=30; var may=31; var jun=30; var jul=31; var ago=31; var sep=30; var oct=31; var nov=30;
  261.  
  262.           var dic=31;
  263.  
  264.           // checa si el año es bisiesto
  265.  
  266.                 var tipo = ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ? true : false;
  267.  
  268.          
  269.  
  270.           if(day<1){
  271.  
  272.               if(tipo==true){if(month==1){ day=ene; }else{ if(month==2){ day=feb2; }else{ if(month==3){ day=mar; }else{ if(month==4){ day=abr;
  273.  
  274.               }else{ if(month==5){ day=may; }else{ if(month==6){ day=jun; }else{ if(month==7){ day=jul; }else{ if(month==8){ day=ago; }else{ if(month==9){ day=sep;
  275.  
  276.               }else{ if(month==10){ day=oct; }else{ if(month==11){ day=nov; }else{ if(month==12){ day=31; } } } } } } } } } } } } }else{ if(month==1){ day=ene; }
  277.  
  278.               else{ if(month==2){ day=feb; }else{ if(month==3){ day=mar; }else{ if(month==4){ day=abr; }else{ if(month==5){ day=may; }else{ if(month==6){ day=jun;
  279.  
  280.               } else{ if(month==7){ day=jul; }else{ if(month==8){ day=ago; }else{ if(month==9){ day=sep; }else{ if(month==10){ day=oct;
  281.  
  282.               }else{ if(month==11){ day=nov; }else{ if(month==12){ day=31; } } } } } } } } } } } } }
  283.  
  284.           }
  285.  
  286.        
  287.  
  288.           //var hor=document.getElementById("hora").value;
  289.  
  290.           var esvalido2=validahora(hor);
  291.  
  292.           if (esvalido2==false)
  293.  
  294.           {
  295.  
  296.               return;
  297.  
  298.           }
  299.  
  300.          
  301.  
  302.           var reshor= hor.split(':');
  303.  
  304.          
  305.  
  306.           var hora = reshor[0];
  307.  
  308.           var minuto = reshor[1];
  309.  
  310.           var segundo = reshor[2];
  311.  
  312.           var unhora = 24;
  313.  
  314.           var unmin = 60;
  315.  
  316.           var unseg = 60;
  317.  
  318.           if( hora== 0){
  319.  
  320.               unhora = 23;
  321.  
  322.           }else{
  323.  
  324.               unhora= 24;
  325.  
  326.           }
  327.  
  328.          
  329.  
  330.           var tothoras= hora - incHour;
  331.  
  332.           var totminutos= minuto - incMinute;
  333.  
  334.           var totsegundos= segundo - incSecond;
  335.  
  336.           if(totsegundos < 0){
  337.  
  338.               var tot= unseg - (incSecond-segundo);
  339.  
  340.               totminutos=totminutos-1;
  341.  
  342.               totsegundos = tot;
  343.  
  344.           }
  345.  
  346.           if(totminutos < 0){
  347.  
  348.                   var tot2 = unmin - (incMinute - minuto);
  349.  
  350.                   tothoras= tothoras - 1;
  351.  
  352.                   totminutos= tot2;
  353.  
  354.           }
  355.  
  356.           if(tothoras < 0){
  357.  
  358.                       var tot3 = unhora -(incHour - hora);
  359.  
  360.                       day = day-1;
  361.  
  362.                       tothoras = tot3;
  363.  
  364.           }
  365.  
  366.          
  367.  
  368.           if(incDay > 0 ){
  369.  
  370.               day=day-1;
  371.  
  372.           }
  373.  
  374.           if(day < 1 ){
  375.  
  376.           month=month-1;
  377.  
  378.           }
  379.  
  380.           if (month <1){
  381.  
  382.               year=year-1;
  383.  
  384.           }
  385.  
  386.           if (month==0){
  387.  
  388.                month=12;        
  389.  
  390.           }
  391.  
  392.          
  393.  
  394.           //asignando las variables de los dias del año
  395.  
  396.           var ene=31; var feb=28; var feb2=29; var mar=31; var abr=30; var may=31; var jun=30; var jul=31; var ago=31; var sep=30; var oct=31; var nov=30;
  397.  
  398.           var dic=31;
  399.  
  400.           // checa si el año es bisiesto
  401.  
  402.           var tipo = ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ? true : false;
  403.  
  404.           if(day<1){
  405.  
  406.               if(tipo==true){if(month==1){ day=ene; }else{ if(month==2){ day=feb2; }else{ if(month==3){ day=mar; }else{ if(month==4){ day=abr;
  407.  
  408.               }else{ if(month==5){ day=may; }else{ if(month==6){ day=jun; }else{ if(month==7){ day=jul; }else{ if(month==8){ day=ago; }else{ if(month==9){ day=sep;
  409.  
  410.               }else{ if(month==10){ day=oct; }else{ if(month==11){ day=nov; }else{ if(month==12){ day=31; } } } } } } } } } } } } }else{
  411.  
  412.               if(month==1){ day=ene; }else{ if(month==2){ day=feb; }else{ if(month==3){ day=mar; }else{ if(month==4){ day=abr; }else{ if(month==5){ day=may;
  413.  
  414.               }else{ if(month==6){ day=jun; }else{ if(month==7){ day=jul; }else{ if(month==8){ day=ago; }else{ if(month==9){ day=sep; }else{ if(month==10){ day=oct;
  415.  
  416.               }else{ if(month==11){ day=nov; }else{ if(month==12){ day=31; } } } } } } } } } } } } }
  417.  
  418.           }
  419.  
  420.           alert ("Resultado de la operacion: \n\n La fecha inicial es " + fe + " con hora: " + hor + "\n\n Con una resta de: " + time + " segundos. \n\n que con la conversion queda: " + incDay + " dia " + incHour + ":" + incMinute + ":" + incSecond + " horas \n\n y como resultado da: \n " + day + "/" + month + "/" + year + " con " + tothoras + ":" + totminutos + ":" + totsegundos );
  421.  
  422.       }
  423.  
  424.  
  425.        
  426.       </script>
  427.  
  428.       <body>
  429. <?php
  430. $datehor='25/01/2011 19:52:16';
  431. $tiempo=69310;
  432. ?>
  433.     <a href="javascript:increaseTime('<?php echo $datehor; ?>',<?php echo $tiempo; ?>)">mandar datos</a>
  434.  
  435.  <!--      <a href="javascript:increaseTime(10,10)">mandar datos</a> -->
  436.        <form id="form1" name="form1" method="post" action="">
  437.  
  438.         <label>
  439.  
  440.           <input name="fecha" type="text" id="fecha" value="25/01/2011" />
  441.  
  442.         </label>
  443.  
  444.         <label>
  445.  
  446.           <input name="hora" type="text" id="hora" value="19:52:16" />
  447.  
  448.         </label>
  449.         <input type="submit" name="btn_mandar" value="Enviar">
  450.  
  451.       </form>  
  452.  
  453.       </body>
  454.  
  455.       </html>