forked from skillrepos/calc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.html
59 lines (46 loc) · 1.27 KB
/
calc.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<html>
<head>
<title>Calc</title>
<script language=javascript type="text/javascript">
var plus,minus,divide,multiply
function initialize(){
plus=document.calc.operator.options[0]
minus=document.calc.operator.options[1]
divide=document.calc.operator.options[2]
multiply=document.calc.operator.options[3]
}
function calculate(){
a = parseInt(document.calc.val1.value)
b = parseInt(document.calc.val2.value)
if (plus.selected)
document.calc.answer.value = a + b
if (minus.selected)
document.calc.answer.value = a - b
if (divide.selected)
document.calc.answer.value = a / b
if (multiply.selected)
document.calc.answer.value = a * b
}
</script>
</head>
<body onLoad="initialize()">
<h2>Calc</h2>
Enter a number in the first box and a number in the second box and select the answer button to see the answer.
<br>
Change the operation via the dropdown selection box if desired.
<form name="calc" action="post">
<input type=text name=val1 size=10>
<select name=operator>
<option value=plus>+
<option value=minus>-
<option value=divide>/
<option value=multiply>*
</select>
<input type=text name=val2 size=10>
=
<input type=text name=answer size=10>
<input type=button value=answer onClick="calculate()">
</form>
<br><br>
</body>
</html>