I have a form that takes inputted information and displays that information on another page. The way that the form is set up is the user enters in a run time, which is separated off with a colon, and enters a penalty time in the same format. The way that the data is being processed and shown is without any leading zeros. For example, for the run time, the user enters in 01:00 and penalty time 00:05. The way this information is being outputted is 1:5, and the way that I want the information to be outputted is 01:05. I know that there is not javascript function that always for retaining leading zeros, but I cannot seem to figure out how to accomplish this.
This is the code that I have.
<script type = "text/javascript">
function calculate()
{
<!-- Variables -->
var dfbrun = document.getElementById("dfb_run").value;
var dfbpen = document.getElementById("dfb_pen").value;
var splitdfbrun = dfbrun.split(':');
var splitdfbpen = dfbpen.split(':');
var dfbmin;
var dfbsec;
var dfbtot;
<!-- DFB Time input -->
dfbmin = parseFloat(splitdfbrun[0].slice(-4)) + parseFloat(splitdfbpen[0].slice(-4))
dfbmin = dfbmin%60;
dfbsec = parseInt(splitdfbrun[1].slice(-2)) + parseInt(splitdfbpen[1].slice(-2))
dfbsec = dfbsec%60;
alert(+dfbmin+ ':' +dfbsec)
dfbtot = +dfbmin+ ':' +dfbsec;
document.getElementById("dfb_com").value = dfbtot;
}
jQuery(function ($) {
$.mask.definitions['~']='[+-]';
$('.run').mask('99:99');
$('.penalty').mask('99:99');
})
</script>
<form method = "GET" action = "RodeoDisplay.php" target = "RodeoDisplay.php">
<table>
<tr>
<td> Site: <input type = "text" value = "DFB" readonly = "true" size = "4"> </td>
<td> Run Time: <input type = "text" size = "5" id = "dfb_run" class = "run" name = "dfb_run">
<td> Penalty: <input type = "text" class = "penalty" size = "5" id = "dfb_pen"> </td>
<td> Completed Time: <input type = "text" readonly = "true" size = "5" id = "dfb_com"> </td>
</tr>
</table>
Would I also be better off using the time function?