SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Simple calculation doesn't work

    I have an input for Fahrenheit in degrees, then a button to start the calculations, then an input box for the result. But the result stays empty. Can you please tell me where my Javascript code went wrong? I am modifying someone else's code form the Internet, and frankly I am guessing at how it works.

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    
    <SCRIPT LANGUAGE="JavaScript">
    
    <!-- Original: Rick Johnson -->
    <!-- Web Site:  http://members.tripod.com/~RickJohnson -->
    <!-- Script from http://javascript.internet.com/math-related/5-function.html -->
    
    }
    <!-- (Fahrenheit - 32) divided by 1.8 = Celsius -->
    function a_minus_b(form) {
    a=eval(form.a.value)
    c=a-32/1.8
    form.ans.value=c
    }
    
    </SCRIPT>
    <title>Convert Temperature</title>
    
    </head>
    <body>
    
        
    <p>(Fahrenheit - 32) &divide; 1.8 = Celsius</p>
    <br>
    <table border="0" cellpadding="5" cellspacing="0" width="100%">
    <tr>
    <td class="alignright">
    <FORM name="formx">Degrees Fahrenheit <input  type=text size=4 value=220 name="a">
     
    <tr>
    <td class="alignright">
    <input type="button" value="Convert" onClick="a_minus_b(this.form)">  
    </td>
    </tr>
    
    <td class="alignright">
    <input size=4 type "number" name="ans" value=>
    </td>
    </tr>
    </FORM>
    </table>
    </p>
    
    </body>
    </html>

  2. #2
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    post the error message you are getting

  3. #3
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kalon View Post
    post the error message you are getting
    I'm playing this back in the iPhone Simulator or on my iPod touch device. I'm not getting any error messages.

    Thanks,
    Steve

  4. #4
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, then to help you debug it you will need to run it in one of the main browsers (preferably Firefox) on some kind of desktop or laptop pc.

    I'm getting syntax errors running it my IE

  5. #5
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    OK, I kept fiddling with it and got it to work with these JS changes:

    HTML Code:
    <FORM name="form">Degrees Fahrenheit <input type=text name=a size=4 value="">
    
    <input type=button value=Convert onClick="a_minus_b(this.form)">  
    
    <input size=4 type=number name=ans value="">


Bookmarks

Posting Permissions

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