JavaScript Notes
Learn to build a multi-step form wizard with animated progress bar in JavaScript. Covers step validation, forward/back navigation, and completion handling.
What You'll Learn
- How to manage a current step index and show/hide form sections
- How to animate a progress bar based on the current step
- How to validate each step before allowing progression
- How to navigate backward and forward without losing entered data
- How to handle the final submission step
Project Overview
A multi-step form breaks a long form into smaller, digestible steps. Each step has a title, a section of inputs, and a visual progress indicator. Users can only advance to the next step when the current step is valid.
Component Structure
How It Works — Flow Diagram
Step-by-Step Build
Step 1 — HTML Structure
Step 2 — State & Config
const TOTAL_STEPS = 4;
let currentStep = 1;Step 3 — Show / Hide Steps
Step 4 — Animate Progress Bar
function updateProgressBar(step) {
const percent = ((step - 1) / (TOTAL_STEPS - 1)) * 100;
document.getElementById("progressFill").style.width = `${percent}%`;
}Step 5 — Validate Current Step
Step 6 — Navigation Buttons
Step 7 — Summary on Completion
function renderSummary() {
const form = document.getElementById("wizardForm");
const data = Object.fromEntries(new FormData(form).entries());
document.getElementById("summaryBox").innerHTML = `
<p><strong>Name:</strong> ${data.firstName} ${data.lastName}</p>
<p><strong>Email:</strong> ${data.email}</p>
<p><strong>Username:</strong> ${data.username}</p>
`;
}Step 8 — Initialize
showStep(1);Console Output
// Step 1: firstName = "", lastName = "Doe" → click Next
validateStep(1) → firstName.classList.add("error") → returns false
→ User stays on step 1 ❌
// Step 1: firstName = "Alice", lastName = "Doe" → click Next
validateStep(1) → all valid → returns true
currentStep = 2 → showStep(2) → progressFill.style.width = "33%"
// Step 3: password = "abc12345", confirm = "abc1234" → click Submit
validateStep(3) → passwords don't match → confirm.classList.add("error") → false
→ User stays on step 3 ❌
// After fixing: submit
currentStep = 4 → showStep(4) → progressFill.style.width = "100%"
renderSummary() → shows name, email, usernameEdge Cases to Handle
| Situation | Expected Behavior |
|---|---|
| Required field empty | Red outline, stay on step |
| Password too short | minLength constraint fires |
| Passwords don't match | Custom check, show error |
| Back from step 3 | Entered data is preserved |
| Submit on step 4 | Button hidden, success state shown |
Challenge Yourself
- Step skipping — click a completed step bubble to jump back to it
- Animated slide — instead of show/hide, slide each step left/right
- Save progress — store partial form data in
sessionStorage - Step icons — replace numbers with icons (👤 📞 🔐 ✅)
- Real submission — send form data to a server with
fetch+ POST request
Best Practices
- Validate before incrementing the step, never after
- Use CSS
display: none / blockor theactiveclass — avoid complex JS animations for simple show/hide - Always clear error styles on the next
inputevent so the user sees instant feedback - Use
FormDatato collect all values cleanly for the summary and submission - Keep
showStep()as the single function that orchestrates all UI updates
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Build a JavaScript Multi-Step Progress Bar - Step by Step Tutorial.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this JavaScript Master Course topic.
Search Terms
javascript-complete-guide, javascript master course, javascript, complete, guide, mini, projects, multi
Related JavaScript Master Course Topics