-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathindex.html
More file actions
42 lines (34 loc) · 1.17 KB
/
index.html
File metadata and controls
42 lines (34 loc) · 1.17 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
39
40
41
42
<!DOCTYPE html>
<html>
<body>
<h2>GraalVM Web Image</h2>
<input type="number" id="num1" value="0">
<br><br>
<input type="number" id="num2" value="0">
<br><br>
<button id="addButton">Add</button>
<button id="clearButton">Clear</button>
<br><br>
<div id="output"></div>
<script src="adder.js"></script>
<script>
GraalVM.run([]).then(() => {
const addButton = document.getElementById("addButton");
const clearButton = document.getElementById("clearButton");
const output = document.getElementById("output");
addButton.addEventListener("click", () => {
const a = parseInt(document.getElementById("num1").value);
const b = parseInt(document.getElementById("num2").value);
// Call the Java add function via WebAssembly
const result = globalThis.adder(a, b);
output.innerText = `Result: ${result}`;
});
clearButton.addEventListener("click", () => {
document.getElementById("num1").value = 0;
document.getElementById("num2").value = 0;
output.innerText = "";
});
});
</script>
</body>
</html>