Skip to content

Commit a6a3871

Browse files
committed
Accessing form elements
1 parent b7d982d commit a6a3871

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

DOM/accessing-form-elements.html

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Accessing form elements</title>
8+
</head>
9+
<body>
10+
<div id="output"></div>
11+
12+
<script>
13+
const output = document.getElementById("output");
14+
output.innerHTML = `
15+
<h1>Accessing form elements</h1>
16+
</br>
17+
<form name='order'>
18+
<label>
19+
Name: <input name="fullname" type="text" value="rakib">
20+
</label>
21+
</br>
22+
<label>
23+
Email: <input name="email" type="email">
24+
</label>
25+
26+
27+
</form>
28+
`;
29+
const form = document.forms.order;
30+
console.log(form);
31+
32+
// const nameInput = form.elements.fullname;
33+
const { fullname, email } = form.elements; //using destructuring
34+
console.log(fullname, email);
35+
console.log(fullname.value);
36+
37+
function handleInput(event) {
38+
console.log(event.target.value); //access value
39+
console.log(event.target.form); //access form
40+
}
41+
fullname.addEventListener("input", handleInput);
42+
</script>
43+
</body>
44+
</html>

0 commit comments

Comments
 (0)