/
calculator.html
140 lines (139 loc) · 4.34 KB
/
calculator.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<html>
<body>
<form name="Calculator" action="">
<table>
<B>
<table class="calci" border=3 width=400 height=270 cellpadding=1 cellspacing=5>
<tr>
<TD colspan=5 align=middle>
<input id="display" name="finalOutput" type="Text" size=40 value="0" width=100% style="height: 70px; width: 530px">
</TD>
</tr>
<tr>
<td>
<center><input name="btnSeven" type="Button" value="7" onclick="numericSelected(this)" style="height: 100px; width: 100px"></center>
</td>
<td>
<center><input name="btnEight" type="Button" value="8" onclick="numericSelected(this)" style="height: 100px; width: 100px"></center>
</td>
<td>
<center><input name="btnNine" type="Button" value="9" onclick="numericSelected(this)" style="height: 100px; width: 100px"></center>
</td>
<td>
<center><input name="btnClear" type="Button" value="C" onclick="Clear()" style="height: 100px; width: 100px"></center>
</td>
<td><center><input name="btnClearEntry" type="Button" value="CE " onclick="ClearEntry()" style="height: 100px; width: 100px"></center>
</td>
</tr>
<tr>
<td>
<center><input name="btnFour" type="Button" value="4" onclick="numericSelected(this)" style="height: 100px; width: 100px"></center>
</td>
<td>
<center><input name="btnFive" type="Button" value="5" onclick="numericSelected(this)" style="height: 100px; width: 100px"></center>
</td>
<td>
<center><input name="btnSix" type="Button" value="6" onclick="numericSelected(this)" style="height: 100px; width: 100px"></center>
</td>
<td align=middle><center><input name="btnPlus" type="Button" value="+" onclick="calculation(this)" style="height: 100px; width: 100px"></center>
</td>
<td align=middle><center><input name="btnMinus" type="Button" value="-" onclick="calculation(this)" style="height: 100px; width: 100px"></center>
</td>
</tr>
<tr>
<td>
<center><input name="btnOne" type="Button" value="1" onclick="numericSelected(this)" style="height: 100px; width: 100px"></center>
</td>
<td>
<center><input name="btnTwo" type="Button" value="2" onclick="numericSelected(this)" style="height: 100px; width: 100px"></center>
</td>
<td>
<center><input name="btnThree" type="Button" value="3" onclick="numericSelected(this)" style="height: 100px; width: 100px"></center>
</td>
<td align=middle><center><input name="btnMultiply" type="Button" value="*" onclick="calculation(this)" style="height: 100px; width: 100px"></center>
</td>
<td align=middle><center><input name="btnDivide" type="Button" value="/" onclick="calculation(this)" style="height: 100px; width: 100px"></center>
</td>
</tr>
<tr>
<td>
<center><input name="btnZero" type="Button" value="0" onclick="numericSelected(this)" style="height: 100px; width: 100px"></center>
</td>
<td>
<center><input name="btnDecimal" type="Button" value="." onclick="numericSelected(this)" style="height: 100px; width: 100px"></center>
</td>
<td colspan=2>
<center><input name="btnEquals" type="Button" value="=" onclick="calculation(this)" style="height: 100px; width: 200px"></center>
</td>
<td>
<center><input name="btnPercent" type="Button" value="%" onclick="Percent()" style="height: 100px; width: 100px"></center>
</td>
</tr>
</table>
</table>
</B>
</form>
</center>
</body>
<style type="text/css">
input:focus {background: red;}
input{font-family:Verdana, Arial, Helvetica, sans-serif; font-size: 28pt;}
</style>
<SCRIPT LANGUAGE="JavaScript">
Flag = false;
var total = 0;
function numericSelected(obj)
{
if(Flag){
document.Calculator.finalOutput.value = obj.value;
Flag = false;
}else{
if(document.Calculator.finalOutput.value == "0"){
document.Calculator.finalOutput.value = obj.value;
}else{
document.Calculator.finalOutput.value += obj.value;
}
}
console.log(this.document);
}
function calculation(obj)
{
Flag = true;
var operator = obj.value;
var calPar = document.Calculator.finalOutput.value;
if(operator != "="){
switch (operator){
case "+":
total = parseInt(total) + parseInt(calPar);
break;
case "-":
total = total - document.Calculator.finalOutput.value;
break;
case "/":
total = total / document.Calculator.finalOutput.value;
break;
case "*":
total = total * document.Calculator.finalOutput.value;
break;
}
}else if(operator == "="){
document.Calculator.finalOutput.value = total;
}
}
function Percent()
{
}
function Clear()
{
document.Calculator.finalOutput.value = 0;
total = 0;
Flag = false;
}
function ClearEntry()
{
document.Calculator.finalOutput.value = 0;
total = 0;
Flag = false;
}
</SCRIPT>
</html>