Código HTML:
Ver original
<html> <script language="javascript"> function padNmb(nStr, nLen){ var sRes = String(nStr); var sCeros = "0000000000"; return sCeros.substr(0, nLen - sRes.length) + sRes; } function stringToSeconds(tiempo){ var sep1 = tiempo.indexOf(":"); var hor = tiempo.substr(0, sep1); var min = tiempo.substr(sep1 + 1); return (Number(min) * 60) + (Number(hor) * 3600)); } function secondsToTime(secs){ var hor = Math.floor(secs / 3600); var min = Math.floor((secs - (hor * 3600)) / 60); return padNmb(hor, 2) + ":" + padNmb(min, 2); } function substractTimes(){ var hora = document.getElementById("hora").value); var secs = stringToSeconds(hora); var secsDif = secs/2; document.getElementById("division").value = secondsToTime(secsDif)); } </script> <body> <form name="fr1" method="post" action=""> <input type"text" id="hora" name="hora" value="01:30"/> <input type="button" value="dividir" onclick="substractTimes()"/> <input type="text" id="division" name="division"/> </form> </body> </html>
Saludos