forked from Pooja9824/Javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
On click with calculation in js.html
55 lines (45 loc) · 1.43 KB
/
On click with calculation in js.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
<html>
<head>
<script type="text/javascript">
function addition() {
var a = document.getElementById("val1").value;
var b = document.getElementById("val2").value;
var sum = 0;
sum = parseInt(a) + parseInt(b);
document.getElementById("result").value = sum;
}
function subtract() {
var a = document.getElementById("val1").value;
var b = document.getElementById("val2").value;
var minus = 0;
minus = parseInt(a) - parseInt(b);
document.getElementById("result").value = minus;
}
function multi() {
var a = document.getElementById("val1").value;
var b = document.getElementById("val2").value;
var multi = 0;
multi = parseInt(a) * parseInt(b);
document.getElementById("result").value = multi;
}
function devision() {
var a = document.getElementById("val1").value;
var b = document.getElementById("val2").value;
var devision = 0;
devision = parseInt(a) / parseInt(b);
document.getElementById("result").value = devision;
}
</script>
</head>
<body>
<h3>Onclick event demo</h3>
<p>Click on the button when form display</p><br>
Enter value A:<input type="text" id="val1" /><br>
Enter value B:<input type="text" id="val2" /><br>
Result:<input type="text" id="result" /><br>
<button id="b1" onClick="addition()">+</button>
<button id="b2" onClick="subtract()">-</button>
<button id="b3" onClick="multi()">*</button>
<button id="b4" onClick="devision()">/</button>
</body>
</html>