qwertyportne
07-31-2011, 08:06 PM
My code converts a running pace to speed in mph. Works fine but posts too many digits after the decmal point in my form. Tried several things but I'm new to javascript and could use some help. Thanks! Oh, my browser is IE8, but the problem is more likely me than it...
--Bill
<code>
<!--This does not work... form.mph.value.toFixed(4) = 60 / (pmin + psec / 60);
Nor this... var mph; mph=mph.toFixed(4);
-->
<html>
<head>
<script language="javascript">
function Speed(MIN, SEC, form)
{
var pmin = parseFloat(MIN);
var psec = parseFloat(SEC);
form.mph.value = 60 / (pmin + psec / 60);
}
function ClearForm(form)
{
form.input_pmin.value = "";
form.input_psec.value = "";
form.mph.value = "";
}
</script>
</head>
<body>
<form name="pace-speed" method="post">
<table style="font-size:14px; font-weight:bold;">
<tr>
<td>PACE</td>
<td><input type="text" name="input_pmin" size="1">:</td>
<td><input type="text" name="input_psec" size="1"></td>
<td width="20"></td>
<td><input TYPE="button" VALUE="Speed" onClick="Speed(this.form.input_pmin.value, this.form.input_psec.value, this.form)"></td>
<td width="1"></td>
<td><input type="text" name="mph" size="8"></td>
<td width="2"></td>
<td><input TYPE="reset" VALUE="Clear" onClick="clearForm(this.form)"></td>
</tr>
</table>
</form>
</body>
</html>
</code>
--Bill
<code>
<!--This does not work... form.mph.value.toFixed(4) = 60 / (pmin + psec / 60);
Nor this... var mph; mph=mph.toFixed(4);
-->
<html>
<head>
<script language="javascript">
function Speed(MIN, SEC, form)
{
var pmin = parseFloat(MIN);
var psec = parseFloat(SEC);
form.mph.value = 60 / (pmin + psec / 60);
}
function ClearForm(form)
{
form.input_pmin.value = "";
form.input_psec.value = "";
form.mph.value = "";
}
</script>
</head>
<body>
<form name="pace-speed" method="post">
<table style="font-size:14px; font-weight:bold;">
<tr>
<td>PACE</td>
<td><input type="text" name="input_pmin" size="1">:</td>
<td><input type="text" name="input_psec" size="1"></td>
<td width="20"></td>
<td><input TYPE="button" VALUE="Speed" onClick="Speed(this.form.input_pmin.value, this.form.input_psec.value, this.form)"></td>
<td width="1"></td>
<td><input type="text" name="mph" size="8"></td>
<td width="2"></td>
<td><input TYPE="reset" VALUE="Clear" onClick="clearForm(this.form)"></td>
</tr>
</table>
</form>
</body>
</html>
</code>