Ver Mensaje Individual
  #9 (permalink)  
Antiguo 06/09/2009, 23:27
Avatar de HackmanC
HackmanC
 
Fecha de Ingreso: enero-2008
Ubicación: Guatemala
Mensajes: 1.817
Antigüedad: 16 años, 3 meses
Puntos: 260
Sonrisa Respuesta: Como optimizar este script para sumar horas?

Hola,

Posiblemente:

Código javascript:
Ver original
  1. <script type="application/javascript">
  2. <!--
  3. function stringToSeconds(s) {
  4.     return new Number(s);
  5. }
  6. function secondsToTime(s) {
  7.     return s;
  8. }
  9. function sumaTiempos() {
  10.     var dev=0;
  11.     for(var i = 0; i < document.forms.Valores.elements.length; i++)
  12.     if (document.Valores.elements[i].type == "text" &&
  13.             document.Valores.elements[i].name == "Valor[]")
  14.         dev += stringToSeconds(document.forms.Valores.elements[i].value);
  15.     return secondsToTime(dev);
  16. }
  17. function calcT3() {  
  18.     document.getElementById("Resultado").value = sumaTiempos();
  19.     return false;
  20. }
  21. //-->
  22. </script>
  23. </head>
  24. <body>
  25. <form id="Valores" name="Valores" method="post" action="" onsubmit="return calcT3();">
  26.     <input type="text" name="Valor[]" />
  27.     <input type="text" name="Valor[]" />
  28.     <input type="text" name="Valor[]" />
  29.     <input type="submit" name="Boton" id="Boton" value="Submit" />
  30.     <input type="text" name="Resultado" id="Resultado" disabled="disabled" />
  31. </form>

Saludos.