Help with this HTML calculator code please?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rse2
    New Member
    • Oct 2011
    • 4

    Help with this HTML calculator code please?

    Hello, I am having a little trouble with this code. I am trying to have it both Add and Subtract in the form. So far it is not displaying the answer to subtraction problems. Can you please give me a hint or help me?

    Code:
    <HTML>
    <HEAD>
    <TITLE>Calculator</TITLE>
      
    <SCRIPT LANGUAGE="JavaScript">
    
    
    function CalculateSum(Atext, Btext, form)
    {
    var A = parseFloat(Atext);
    var B = parseFloat(Btext);
    form.Answer.value = A + B;
    form.sub.value = A + B;
    }
    
    </SCRIPT>
    </HEAD>
    
    <BODY>
    
    <P><FONT SIZE="+2">Simple Adder</FONT></P>
    
    <FORM NAME="Calculator" METHOD="post">
    <P>Enter a number: <INPUT TYPE=TEXT NAME="input_A" SIZE=10></P>
    <P>Enter a number: <INPUT TYPE=TEXT NAME="input_B" SIZE=10></P>
    <P><INPUT TYPE="button" VALUE="Add Numbers" name="AddButton" onClick="CalculateSum(this.form.input_A.value, this.form.input_B.value, this.form)"></P>
    <P><INPUT TYPE="button" VALUE="Subtract Numbers" name="subButton" onClick="Calculatediff(this.form.input_s.value, this.form.input_B.value, this.form)"></P>
    <P>Answer = <INPUT TYPE=TEXT NAME="Answer" SIZE=12></P>
    </FORM>
    
    </BODY>
    </HTML>
    Last edited by NeoPa; Oct 5 '11, 10:47 PM. Reason: Fixed [CODE] tags
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    WHere is your Calculatediff function?

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      Also, there's no need, they can just use the add and put in negative numbers.

      Comment

      Working...