View Full Version : adding error

08-01-2002, 11:12 PM
i have the following script:

<form name="converter">
<table border="1" width="50%">
<td width="33%">&nbsp;</td>
<td width="33%">Distance</td>
<td width="34%">Height</td>
<td width="33%">Naithsmiths Rule* mins</td>
<td width="33%">
<input type="text" value="4" name="nrd"> </td>
<td width="34%"><input type="text" name="nrh" size="20" onChange="calc2()" value="1"></td>
<td width="33%">My info#</td>
<td width="33%">
<input type="text" name="md" onChange="calc2()"> </td>
<td width="34%"><input type="text" name="myh" size="20" onChange="calc2()"></td>
<td width="33%">Time</td>
<td width="33%">
<input type="text" name="DT"></td>
<td width="34%"><input type="text" name="HT" size="20"></td>
<td width="33%">Total Time (mins)</td>
<td width="67%" colspan="2"><input type="text" name="tot" size="20"></td>
<p>* Height = 1 Min/10 meters up&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Distance = 1KM/15 Mins</p>
<p># Distance =&nbsp;
Height = Meters
<script language="javascript">

//calculate function
function calc2(){

var nd = document.converter.nrd.value
var myd = document.converter.md.value
//height variables
var nh = document.converter.nrh.value
var mh = document.converter.myh.value

//totals fields
var d = document.converter.DT.value
var h = document.converter.HT.value

var calculated = nd * myd
var calculatedh = nh * mh
var total = d + h

//write in text box

but i need to get the totals of the claculated distance and the calculated height gain times and shot them in the box tot.
the line which is the problem is:
var total = d + h
as all the code does say i was adding 12 and 5 you would get 17 in your head but this would tell you 125.
anyone know how to correct this?

thanks in advance

Roy Sinclair
08-01-2002, 11:18 PM
var total = Number(d) + Number(h)

08-02-2002, 09:52 PM
i will know for next time, a figure the long way of doing it and got the long way to work, but now i know the sohrtway for next time.