Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: adding error

  1. #1
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts

    adding error

    i have the following script:

    Code:
    <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
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    var total = Number(d) + Number(h)

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •