Calculator

• Aug 21, 2001, 19:06
Disk-t
Calculator
I can't seem to get the subtraction, multiplication, and division functions to work:

<script>
function getit() {
else if (document.former.oper.value == "-") {subtract()}
else if (document.former.oper.value == "*") {multiply()}
else if (document.former.oper.value == "/") {divide()}
}

var num1 = document.former.num1.value;
var num2 = document.former.num2.value;

}
function subtract() {
var num1 = document.former.num1.value;
var num2 = document.former.num2.value;

}
function multiply() {
var num1 = document.former.num1.value;
var num2 = document.former.num2.value;

}
function divide() {
var num1 = document.former.num1.value;
var num2 = document.former.num2.value;

}

</script>
<form name="former">
<input type="text" name="num1">

<select size="1" name="oper">
<option selected value="+">+</option>
<option>-</option>
<option>*</option>
<option>/</option>
&nbsp;
</select><input type="text" name="num2">
<input type="button" value="submit" onClick="getit()">

</form>
• Aug 21, 2001, 19:08
Anarchos
It's prolly because you don't have parseInt in those, but you do for addition.
• Aug 21, 2001, 22:49
Disk-t
I thought parseInt was only needed for addition, because '+' is also used when writing sentences from different forms. Combining them instead of adding.
• Aug 21, 2001, 22:52
Anarchos
Ahhh, it's because of the way you're accessing the <select>. It should be like this:

var o = document.former.oper;
var oper = o.options[o.selectedIndex].value;
• Aug 24, 2001, 11:55
Disk-t
I just did it using radio buttons. Much easier.:flippy: