469,357 Members | 1,857 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,357 developers. It's quick & easy.

Help with this HTML calculator code please?

4
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?

Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <HEAD>
  3. <TITLE>Calculator</TITLE>
  4.  
  5. <SCRIPT LANGUAGE="JavaScript">
  6.  
  7.  
  8. function CalculateSum(Atext, Btext, form)
  9. {
  10. var A = parseFloat(Atext);
  11. var B = parseFloat(Btext);
  12. form.Answer.value = A + B;
  13. form.sub.value = A + B;
  14. }
  15.  
  16. </SCRIPT>
  17. </HEAD>
  18.  
  19. <BODY>
  20.  
  21. <P><FONT SIZE="+2">Simple Adder</FONT></P>
  22.  
  23. <FORM NAME="Calculator" METHOD="post">
  24. <P>Enter a number: <INPUT TYPE=TEXT NAME="input_A" SIZE=10></P>
  25. <P>Enter a number: <INPUT TYPE=TEXT NAME="input_B" SIZE=10></P>
  26. <P><INPUT TYPE="button" VALUE="Add Numbers" name="AddButton" onClick="CalculateSum(this.form.input_A.value, this.form.input_B.value, this.form)"></P>
  27. <P><INPUT TYPE="button" VALUE="Subtract Numbers" name="subButton" onClick="Calculatediff(this.form.input_s.value, this.form.input_B.value, this.form)"></P>
  28. <P>Answer = <INPUT TYPE=TEXT NAME="Answer" SIZE=12></P>
  29. </FORM>
  30.  
  31. </BODY>
  32. </HTML>
Oct 5 '11 #1

✓ answered by johny10151981

WHere is your Calculatediff function?

2 2288
johny10151981
1,059 1GB
WHere is your Calculatediff function?
Oct 6 '11 #2
Rabbit
12,516 Expert Mod 8TB
Also, there's no need, they can just use the add and put in negative numbers.
Oct 6 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Fabian | last post: by
6 posts views Thread by Rafael | last post: by
1 post views Thread by KiMcHeE | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.