JavaScript Form Validation
(Simple Explanation)
Topic 3.3 | Web Design Technology
Step 1: Detect the Form
Submission
• [Link]('registrationForm').
addEventListener('submit', function (event) {
• 👉 Finds the form with ID 'registrationForm'
and waits for it to be submitted.
Step 2: Prevent Default Behavior
• [Link]();
• [Link]();
• 👉 Stops the form from reloading the page. We
will check validation first.
Step 3: Store the Form in a Variable
• const form = [Link];
• 👉 Saves the form that was submitted into a
variable called 'form'.
Step 4: Check if the Form is Valid
• if ([Link]()) {
• alert('Form submitted successfully!');
• }
• 👉 Checks if all inputs meet their rules (like
required, email format).
• 👉 If valid, shows a success message.
Step 5: Show Error Messages if
Invalid
• else {
• [Link]('was-validated');
• }
• 👉 Adds the Bootstrap class 'was-validated' to
highlight invalid fields.
• 👉 Shows red borders and error text under each
field.
✅ Summary
• ✔ Prevents form from auto-submitting.
• ✔ Checks whether inputs are valid.
• ✔ Shows a success message if valid.
• ✔ Highlights invalid fields using Bootstrap if
errors exist.