-
Notifications
You must be signed in to change notification settings - Fork 0
/
two text.html
50 lines (41 loc) · 1.48 KB
/
two text.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form>
<input type="text" placeholder="enter a number 1" id="no1">
<input type="text" placeholder="enter a number 1" id="no2"> <br><br>
<input type="button" value="Addition" onclick="add()">
<input type="button" value="Subtrsction" onclick="sub()"> <br><br>
<label for="">Result Box</label>
<input type="text" id="result">
</form>
<script>
function add() {
var no1 = parseFloat(document.getElementById("no1").value);
var no2 = parseFloat(document.getElementById("no2").value);
if (!no1 || !no2) {
alert("Don't leave the input fields blank");
} else {
var result = no1 + no2;
document.getElementById("result").value = "Addition = " + result;
}
}
function sub() {
var no1 = parseFloat(document.getElementById("no1").value);
var no2 = parseFloat(document.getElementById("no2").value);
if (isNaN(no1) || isNaN(no2)) {
alert("Don't leave the input fields blank");
} else {
var result = no1 - no2;
document.getElementById("result").value = "Subtraction = " + result;
}
}
</script>
</script>
</body>
</html>