Here is a really simple JavaScript calculator - with just 5 functions! (Add, subtract, multiply, divide, and power) This example can help you see how JavaScript evaluates math functions! Check it out!
Add the below code to the <body> section of your page:
<scriptlanguage="javascript"type="text/javascript"> /* Visit http://www.yaldex.com/
for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin function
a_plus_b(form){ a=eval(form.a.value) b=eval(form.b.value) c=a+b form.ans.value=
c } function
a_minus_b(form){ a=eval(form.a.value) b=eval(form.b.value) c=a-b form.ans.value=c } function
a_times_b(form){ a=eval(form.a.value) b=eval(form.b.value) c=a*b form.ans.value=c } function
a_div_b(form){ a=eval(form.a.value) b=eval(form.b.value) c=a/b form.ans.value=
c } function
a_pow_b(form){ a=eval(form.a.value) b=eval(form.b.value) c=Math.pow(a,
b) form.ans.value=
c } // End --> </script> <center> <FORMname="formx"><inputtype=textsize=4value=12name="a"> <inputtype="button"value="
+ "onClick="a_plus_b(this.form)"> <inputtype="button"value="
- "onClick="a_minus_b(this.form)"> <inputtype="button"value="
x "onClick="a_times_b(this.form)"> <inputtype="button"value="
/ "onClick="a_div_b(this.form)"> <inputtype="button"value="
^ "onClick="a_pow_b(this.form)"> <inputtype="number"size=4value=3name="b">
= <inputtype"number"value=0name="ans"size=9>
</FORM> </center>