File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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>
You can’t perform that action at this time.
0 commit comments