-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform_input.html
More file actions
38 lines (32 loc) · 1.11 KB
/
form_input.html
File metadata and controls
38 lines (32 loc) · 1.11 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Add or Multiply Two Numbers</title>
</head>
<body>
<h2>Add or Multiply Two Numbers</h2>
<form onsubmit="calculate(event)">
<label>Enter First Number:</label>
<input type="number" id="num1" required><br><br>
<label>Enter Second Number:</label>
<input type="number" id="num2" required><br><br>
<button type="button" onclick="addNumbers()">Add</button>
<button type="button" onclick="multiplyNumbers()">Multiply</button>
</form>
<h3 id="result"></h3>
<script>
function addNumbers() {
let a = parseFloat(document.getElementById("num1").value);
let b = parseFloat(document.getElementById("num2").value);
let sum = a + b;
document.getElementById("result").innerHTML = "Sum = " + sum;
}
function multiplyNumbers() {
let a = parseFloat(document.getElementById("num1").value);
let b = parseFloat(document.getElementById("num2").value);
let product = a * b;
document.getElementById("result").innerHTML = "Product = " + product;
}
</script>
</body>
</html>