Allows runners to calculate their time, distance covered, or pace by entering the other two values. Distance and pace can be converted between various measurements. A great 3-in-1 script for runners!
Add the below code to the <body> section of your page:
<scriptlanguage="javascript"type="text/javascript"> /* Visit http://www.yaldex.com/
for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin var
TIME =1; var
DISTANCE =2; var
PACE =3; var
MILES =0; var
METERS =1; var
KILOMETERS =2; var
TRUE =1; var
FALSE =0;
function
calcIT(){ min=document.Calc.timeM.value; sec=document.Calc.timeS.value; time =(min*1)+(sec
/60); distance =document.Calc.distance.value; minP =document.Calc.paceM.value; secP =document.Calc.paceS.value; pace =(minP
*1)+(secP
/60); result =document.Calc.CalcWhat.options[document.Calc.CalcWhat.selectedIndex].value; if(result
==
TIME){ distConversion(TRUE); paceConversion(TRUE); time =
distance *
pace; min=document.Calc.timeM.value=Math.floor(time); document.Calc.timeS.value=Math.round(60*(time
-min)); } else
if(result
==
DISTANCE){ paceConversion(TRUE); distance =
time /
pace; distConversion(FALSE); document.Calc.distance.value=
decimalPlaces(distance,2);
} else if(result
==
PACE){ distConversion(TRUE); pace =
time /
distance; paceConversion(FALSE); minP =Math.floor(pace); secP =Math.round(60*(pace
-
minP)); if(secP
==60){ minP++; secP =0;
} document.Calc.paceM.value=
minP; document.Calc.paceS.value=
secP; }
} function
distConversion(toMeters){ if(document.Calc.optDist[MILES].checked){ distance =(toMeters)?(distance
*1609):(distance
/1609); } else if(document.Calc.optDist[METERS].checked){} else if(document.Calc.optDist[KILOMETERS].checked){ distance =(toMeters)?(distance
*1000):(distance
/1000); }
} function
paceConversion(toMeters){ if(document.Calc.optPace[MILES].checked){ pace =(toMeters)?(pace
/1609):(pace
*1609); } else if(document.Calc.optPace[METERS].checked){ pace =(toMeters)?(pace
/400):(pace
*400);
} else if(document.Calc.optPace[KILOMETERS].checked){ pace =(toMeters)?(pace
/1000):(pace
*1000); }
} function
decimalPlaces(val,
places){ factor =1; for(i
=0;
i <
places;
i++){ factor *=10;
} val *=
factor; val =Math.round(val); val /=
factor; return
val;
} function
checkCalc(){ choice =document.Calc.CalcWhat.selectedIndex; if(choice
==0){ alert('Please
select what you would like to calculate: time, distance, or pace.');
} if(choice
==1){ document.Calc.timeM.value=''; document.Calc.timeS.value=''; alert('To
calculate your time, enter the distance traveled and your pace time per
distance interval.');
} if(choice
==2){ document.Calc.distance.value=''; alert('To
calculate your distance, enter the time elapsed and your pace time per
distance interval.');
} if(choice
==3){ document.Calc.paceM.value=''; document.Calc.paceS.value=''; alert('To
calculate your pace, enter the time elapsed and the distance traveled.'); }
} // End --> </script> <formname="Calc"> <tableborder=1cellpadding=10cellspacing=0>
<tr>
<td> <center>
<fontsize=+1><b>Calculate
Your: </b></font> <selectname=CalcWhatonChange="checkCalc();">
<optionvalue=0selected>-
Choose - <optionvalue=1>Time <optionvalue=2>Distance <optionvalue=3>Pace </select> </center>
<br><br> Time:
<input
type=textname=timeMsize=9>
minutes, <inputtype=textname=timeSsize=9>
seconds <br><br> Distance: <inputtype=textname=distancesize=9><br> (Measure in: <inputtype=radioname="optDist"value="miles"checked>
Miles <inputtype=radioname="optDist"value="kilometers">
Kilometers <inputtype=radioname="optDist"value="meters">
Meters) <br><br> Pace time: <inputtype=textname=paceMsize=9>
minutes, <inputtype=textname=paceSsize=9>
seconds<br> (Pace distance: <inputtype=radioname="optPace"value="miles"checked>Miles
<inputtype=radioname="optPace"value="400meters">400m
<inputtype=radioname="optPace"value="kilometers">Kilometers)
</td>
</tr>
<tr>
<td
colspan=2align=center> <inputtype=buttonvalue="Calculate"onClick="calcIT()"> </td>
</tr>
</table> </form>