...

View Full Version : adding error



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



<form name="converter">
<table border="1" width="50%">
<tr>
<td width="33%">&nbsp;</td>
<td width="33%">Distance</td>
<td width="34%">Height</td>
</tr>
<tr>
<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>
</tr>
<tr>
<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>
</tr>
<tr>
<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>
</tr>
<tr>
<td width="33%">Total Time (mins)</td>
<td width="67%" colspan="2"><input type="text" name="tot" size="20"></td>
</tr>
</table>
&nbsp;
<p>* Height = 1 Min/10 meters up&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Distance = 1KM/15 Mins</p>
<p># Distance =&nbsp;
Meters&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Height = Meters
<BR>
</p>
</form>
<script language="javascript">

//calculate function
function calc2(){

//variables
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
document.converter.DT.value=calculated
document.converter.HT.value=calculatedh
document.converter.tot.value=total
}
</script>


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
scroots

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

scroots
08-02-2002, 08:52 PM
cheers
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.
ta
scroots



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum