Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/01/2011, 18:03
Avatar de skiper0125
skiper0125
 
Fecha de Ingreso: octubre-2010
Ubicación: $this->Mexico('Toluca');
Mensajes: 1.127
Antigüedad: 14 años, 4 meses
Puntos: 511
Pregunta Problemas con la funcion en javascrip

Necesito ayuda, el problema es que en la suuiguinte funcion, cuando obtengo los datos del formulario me funciona adecuadamente.

Y cuando mando los datos directos no funciona por q sera, no lo se ya que he intentado modificarla pero no lo puedo solucionar ayudenme necesito solucionar este problema
donde tengo el error:
Código Javascript:
Ver original
  1. <script language="javascript" type="text/javascript">
  2.  
  3. function Validar(Cadena){  
  4.     var fe=Cadena;
  5.    
  6.     var Dia = parseInt(fe.substr(0,2));
  7.     var Mes = parseInt(fe.substr(3,4));
  8.     var Ano = parseInt(fe.substr(6,4));
  9.    
  10.     var mensaje="";
  11.     if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900) mensaje= "Año inválido";
  12.     if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12) mensaje = "Mes incorrecto";
  13.     if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31)mensaje = "Día inválido";  
  14.      
  15.     if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {  
  16.         if (Mes==2 && Dia > 28 || Dia>30) {  
  17.             mensaje= "dia invalido";
  18.         }  
  19.     }  
  20.          
  21.      if (mensaje!="") {
  22.         alert("Atencion, la fecha es incorrecta");
  23.         return false;
  24.     } else {
  25.        
  26.         return true;
  27.     }
  28.  
  29. }  
  30.  
  31.  
  32. function validahora(str)
  33. {
  34.  
  35.     var mensaj=str;
  36.     var des="";
  37.     var reshor2= mensaj.split(':');
  38.    
  39.     var hora4= reshor2[0];
  40.     var minuto4 = reshor2[1];
  41.     var segundo4 = reshor2[2];
  42.    
  43.     if(hora4 > 24) des="error";
  44.     if(minuto4 > 60) des="error";
  45.     if(segundo4 > 60) des="error";
  46.    
  47.     if (des!="") {
  48.         alert("Error en la hora: \n\n introduce la fecha en este tipo HH:MM:SS ");
  49.         return false;
  50.     } else {
  51.        
  52.         return true;
  53.     }
  54.  
  55.  
  56. }
  57.  
  58.  
  59.  
  60. function increaseTime(datehor,time)
  61. {
  62.    
  63.     var inc = time;
  64.     var de = datehor;
  65.    
  66.     var cot = de.split(' ');
  67.    
  68.     var fe = toc[0];
  69.     var hor = toc[1];
  70.    
  71.    
  72.     var incSecond= 0;
  73.     var incMinute= 0;
  74.     var incHour= 0;
  75.     var incDay= 0;
  76.     var incMonth= 0;
  77.     var incYear= 0;
  78.     while (inc >0)
  79.     {
  80.             if (inc < 86400)   
  81.             {
  82.                 if (inc < 3600)
  83.                 {
  84.                     if (inc < 60)
  85.                     {
  86.                         //Segundos
  87.                         incSecond=inc;
  88.                         inc=inc-incSecond;
  89.                     }
  90.                     else
  91.                     {
  92.                         //Minutos
  93.                         incMinute=Math.floor(inc/60);
  94.                         inc=inc-(incMinute*60);                
  95.                     }
  96.                 }
  97.                 else
  98.                 {
  99.                     //Horas
  100.                     incHour=Math.floor(inc/3600);
  101.                     inc=inc-(incHour*3600);
  102.                 }
  103.             }
  104.             else
  105.             {
  106.                 //Dias
  107.                 incDay=Math.floor(inc/86400);
  108.                 inc=inc-(incDay*86400);
  109.             }  
  110.             //return resta(incDay,incHour,incMinute);
  111.            
  112.     }
  113.    
  114.     //descomponer las fechas en dia mes y año  
  115.     //var fe=document.getElementById("fecha").value;
  116.     var esvalido=Validar(fe);
  117.     if (esvalido==false)
  118.     {
  119.         return;
  120.     }
  121.    
  122.     var day = parseInt(fe.substr(0,2));
  123.     var month = parseInt(fe.substr(3,4));
  124.     var year = parseInt(fe.substr(6,4));
  125.    
  126.     //comprobar las restas de las los dias meses y años
  127.    
  128.     if(incDay > 0 ){
  129.         day=day-1;
  130.     }
  131.     if(day < 1 ){
  132.     month=month-1;
  133.     }
  134.     if (month <1){
  135.         year=year-1;
  136.     }
  137.     if (month==0){
  138.          month=12;         
  139.     }
  140.    
  141.     //asignando las variables de los dias del año  
  142.     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;
  143.     var dic=31;
  144.    
  145.     // checa si el año es bisiesto 
  146.     var tipo = ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ? true : false;
  147.    
  148.     if(day<1){
  149.         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;
  150.         }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;
  151.         }else{ if(month==10){ day=oct; }else{ if(month==11){ day=nov; }else{ if(month==12){ day=31; } } } } } } } } } } } } }else{ if(month==1){ day=ene; }
  152.         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;
  153.         } else{ if(month==7){ day=jul; }else{ if(month==8){ day=ago; }else{ if(month==9){ day=sep; }else{ if(month==10){ day=oct;
  154.         }else{ if(month==11){ day=nov; }else{ if(month==12){ day=31; } } } } } } } } } } } } }
  155.     }
  156.  
  157.     //var hor=document.getElementById("hora").value;
  158.     var esvalido2=validahora(hor);
  159.     if (esvalido2==false)
  160.     {
  161.         return;
  162.     }
  163.    
  164.     var reshor= hor.split(':');
  165.    
  166.     var hora = reshor[0];
  167.     var minuto = reshor[1];
  168.     var segundo = reshor[2];
  169.    
  170.    
  171.     var unhora = 24;
  172.     var unmin = 60;
  173.     var unseg = 60;
  174.    
  175.     if( hora== 0){
  176.         unhora = 23;
  177.     }else{
  178.         unhora= 24;
  179.     }
  180.    
  181.     var tothoras= hora - incHour;
  182.     var totminutos= minuto - incMinute;
  183.     var totsegundos= segundo - incSecond;
  184.    
  185.    
  186.    
  187.    
  188.    
  189.     if(totsegundos < 0){
  190.         var tot= unseg - (incSecond-segundo);
  191.         totminutos=totminutos-1;
  192.         totsegundos = tot;
  193.     }
  194.     if(totminutos < 0){
  195.             var tot2 = unmin - (incMinute - minuto);
  196.             tothoras= tothoras - 1;
  197.             totminutos= tot2;
  198.     }
  199.     if(tothoras < 0){
  200.                 var tot3 = unhora -(incHour - hora);
  201.                 day = day-1;
  202.                 tothoras = tot3;
  203.     }
  204.    
  205.     if(incDay > 0 ){
  206.         day=day-1;
  207.     }
  208.     if(day < 1 ){
  209.     month=month-1;
  210.     }
  211.     if (month <1){
  212.         year=year-1;
  213.     }
  214.     if (month==0){
  215.          month=12;         
  216.     }
  217.    
  218.     //asignando las variables de los dias del año  
  219.     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;
  220.     var dic=31;
  221.     // checa si el año es bisiesto 
  222.     var tipo = ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ? true : false;
  223.    
  224.            
  225.  
  226.     if(day<1){
  227.         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;
  228.         }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;
  229.         }else{ if(month==10){ day=oct; }else{ if(month==11){ day=nov; }else{ if(month==12){ day=31; } } } } } } } } } } } } }else{ 
  230.         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;
  231.         }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;
  232.         }else{ if(month==11){ day=nov; }else{ if(month==12){ day=31; } } } } } } } } } } } } }
  233.     }
  234.  
  235.    
  236.     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 );
  237.    
  238. }
  239.  
  240.    
  241. </script>
  242.  
  243. <body>
  244.  
  245.  
  246. <?php
  247.  
  248. $datehor='25/01/2011 19:52:16';
  249. $tiempo=69310;
  250.  
  251. ?>
  252.  
  253. <a href="javascript:increaseTime(<?php echo $fe; ?>,<?php echo $fe; ?>,<?php echo $tiempo; ?>)">mandar datos</a>