Originally Posted by
tactcalplaya
i will not teach you how to do something bad.
You just did! First, just a little thing, HTML tags are written in lower case since years but well. The other thing is your use of eval() which is just evil! It should be parseFloat(), parseInt() or Number() as eval() should not be used as it interprets input as JavaScript and is a potential security issue. Also it makes your whole code pretty blown up with all these functions.
One input field and one output could do the same as eval() does calculate stuff like "4+2+1+7*4" pretty well. And even without eval() you don't need as much functions. Here is an example that uses a second parameter to select the performed operation.
Code:
function calculate(form, operation)
{
a = parseInt(form.a.value);
b = parseInt(form.b.value);
switch(operation)
{
case 1: c = a + b; break;
case 2: c = a - b; break;
case 3: c = a * b; break;
case 4: c = a / b; break;
case 5: c = Math.pow(a, b); break;
}
form.ans.value = c;
}
<input type="button" value=" + " onClick="calculate(this.form, 1)">
<input type="button" value=" - " onClick="calculate(this.form, 2)">
<input type="button" value=" x " onClick="calculate(this.form, 3)">
<input type="button" value=" / " onClick="calculate(this.form, 4)">
<input type="button" value=" ^ " onClick="calculate(this.form, 5)">