|
10 | 10 | </head>
|
11 | 11 |
|
12 | 12 |
|
13 |
| - <script> |
| 13 | + <!-- ORIGINAL Exampler --> |
| 14 | + <!-- <script> |
14 | 15 | window.addEventListener("load", function() {
|
15 | 16 | let form = document.querySelector("form");
|
| 17 | + |
16 | 18 | form.addEventListener("submit", function(event) {
|
17 | 19 | alert("submit clicked");
|
18 | 20 | });
|
19 | 21 | });
|
| 22 | + </script> --> |
| 23 | + |
| 24 | + |
| 25 | + <!-- Add Validation - Get Reference to Inputs --> |
| 26 | + <!-- <script> |
| 27 | + window.addEventListener("load", function() { |
| 28 | + let form = document.querySelector("form"); |
| 29 | + |
| 30 | + form.addEventListener("submit", function(event) { |
| 31 | + let usernameInput = document.querySelector("input[name=username]"); |
| 32 | + // Alert the Current Value found in the Username Input |
| 33 | + alert("username: " + usernameInput.value); |
| 34 | + }); |
| 35 | + }); |
| 36 | + </script> --> |
| 37 | + |
| 38 | + <!-- Add Validation - Alert the Input Values When Submitted --> |
| 39 | + <!-- <script> |
| 40 | + window.addEventListener("load", function() { |
| 41 | + let form = document.querySelector("form"); |
| 42 | + |
| 43 | + form.addEventListener("submit", function(event) { |
| 44 | + let usernameInput = document.querySelector("input[name=username]"); |
| 45 | + let teamName = document.querySelector("input[name=team]"); |
| 46 | +
|
| 47 | + |
| 48 | + // Uses a Conditional statement to verify ALL fields are filled |
| 49 | + if (usernameInput.value === "" || teamName.value === "") { |
| 50 | + alert("ALL fields are required!"); |
| 51 | + } |
| 52 | + }); |
| 53 | + }); |
| 54 | + </script> --> |
| 55 | + |
| 56 | + <!-- PREVENT Form Submission until ALL inputs have Valid values --> |
| 57 | + <script> |
| 58 | + window.addEventListener("load", function() { |
| 59 | + let form = document.querySelector("form"); |
| 60 | + |
| 61 | + form.addEventListener("submit", function(event) { |
| 62 | + let usernameInput = document.querySelector("input[name=username]"); |
| 63 | + let teamName = document.querySelector("input[name=team]"); |
| 64 | + |
| 65 | + |
| 66 | + // Uses a Conditional statement to verify ALL fields are filled |
| 67 | + if (usernameInput.value === "" || teamName.value === "") { |
| 68 | + alert("ALL fields are required!"); |
| 69 | + |
| 70 | + // STOPS the Form Submission |
| 71 | + event.preventDefault(); |
| 72 | + } |
| 73 | + }); |
| 74 | + }); |
20 | 75 | </script>
|
21 | 76 |
|
22 | 77 | <body>
|
23 | 78 | <form
|
24 | 79 | method="POST"
|
25 | 80 | action="https://handlers.education.launchcode.org/request-parrot">
|
26 | 81 |
|
27 |
| - <label>Username </label> |
28 |
| - <input type="text" name="username"> |
| 82 | + <label>Username <input type="text" name="username"></label> |
| 83 | + |
29 | 84 |
|
30 | 85 | <label>Team Name <input type="text" name="team"></label>
|
31 | 86 | <button>Submit</button>
|
|
0 commit comments