-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.html
45 lines (40 loc) · 1.19 KB
/
form.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Web Component Test</title>
<link rel="stylesheet" href="styles.css">
<script src="common-wc.js"></script>
<script src="form-wc.js"></script>
</head>
<body>
<my-header title="Form Examples" anchor></my-header>
<h3>Using Elements Internals</h3>
<form id="name-form">
<label for="input-name" id="label-name">
Enter Name:
</label>
<div>
<my-name-input id="input-name"></my-name-input>
</div>
<div>
<input type="submit" value="Enter"></input>
</div>
</form>
<div id="output"></div>
<script>
const form = document.querySelector("#name-form");
form.addEventListener("submit", (e) => {
console.log("Form submitted: ", e);
// display the input value
const output = document.getElementById("output");
output.innerHTML = `Input value: ${e.target[0].value}`;
// do not refresh the page (the default form action)
e.preventDefault();
});
</script>
<hr>
<a href="https://github.com/cdoremus/web-component-demos/blob/main/form.html">Source Code</a>
</body>
</html>