Ver Mensaje Individual
  #3 (permalink)  
Antiguo 03/02/2011, 11:18
clavena
 
Fecha de Ingreso: septiembre-2010
Ubicación: Santiago, Chile
Mensajes: 47
Antigüedad: 13 años, 8 meses
Puntos: 0
Respuesta: En que me Equivoco??

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  4. <title>Test Cálculo UF</title>
  5.  
  6. <script language="javascript">
  7.    
  8.     function padNmb(nStr, nLen){
  9.     var sRes = String(nStr);
  10.     var sCeros = "0000000000";
  11.     return sCeros.substr(0, nLen - sRes.length) + sRes;
  12.    }
  13.  
  14.    function secsToTime(time) {
  15.    var hora = Math.floor(time / 3600);
  16.    var min = Math.floor ((time - (hora * 3600)) / 60 );
  17.    return padNmb(hor, 2) + ":" + padNmb(min, 2);
  18.    }
  19.    
  20.    function stringToSeconds(time_1, time_2) {
  21.         return (Number(time_1) * 3600) + (Number(time_2) * 60);
  22.    }
  23.    
  24.    
  25.    function substractTimes(hr_1, min_1, hr_2, min_2) {
  26.    var secs1 = stringToSeconds(hr_1, min_1);
  27.    var secs2 = stringToSeconds(hr_2, min_2);
  28.    var secsDif = secs1 - secs2;
  29.    return secsToTime(secsDif);
  30.    }
  31.  
  32.    function calcHr(){
  33.     with (document.frm)
  34.      uf.value = substractTimes(hr_2.value, min_2.value, hr_1.value, min_1.value);
  35.    }
  36.  
  37.  
  38. </head>
  39.  
  40. <p>&nbsp;</p>
  41. <p>&nbsp;</p>
  42. <p>&nbsp;</p>
  43.     <blockquote>
  44.       <blockquote>
  45.         <blockquote>
  46.           <blockquote>
  47.             <blockquote>
  48.               <blockquote>
  49.                 <form id="frm" name="frm">
  50.                   <table width="350" align="center">
  51.                     <tr>
  52.                       <td width="157"><div align="right">Hora Inicio: </div></td>
  53.                       <td width="89">
  54.                         <div align="right">
  55.                           <input name="hr_1" type="text" id="hr_1" size="5" />
  56.                       :                      </div></td>
  57.                       <td width="90"><div align="left">
  58.                         <input name="min_1" type="text" id="min_1" size="5" />
  59.                       </div></td>
  60.                     </tr>
  61.                     <tr>
  62.                       <td><div align="right">Hora Termino: </div></td>
  63.                       <td>
  64.                         <div align="right">
  65.                           <input name="hr_2" type="text" id="hr_2" size="5" />
  66.                           :
  67.                         </div>
  68.                       <div align="right"></div><div align="right"></div></td>
  69.                       <td><div align="left">
  70.                         <input name="min_2" type="text" id="min_2" size="5" />
  71.                       </div></td>
  72.                     </tr>
  73.                     <tr>
  74.                       <td colspan="3">
  75.                        
  76.                         <div align="center">
  77.                           <input type="button" name="Calcular" value="Calcular" onclick="calcHr()" />
  78.                         </div></td>
  79.                     </tr>
  80.                     <tr>
  81.                       <td><div align="right">Total UF: </div></td>
  82.                       <td colspan="2"><div align="center">
  83.                           <input name="uf" type="text" id="uf" />
  84.                       </div></td>
  85.                     </tr>
  86.                   </table>
  87.                 </form>
  88.               </blockquote>
  89.             </blockquote>
  90.           </blockquote>
  91.         </blockquote>
  92.       </blockquote>
  93.     </blockquote>
  94. </body>
  95. </html>