Skip to content

PavanKoder27/advanced-dom-javascript-assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Advanced DOM & JavaScript Assignment

🎯 A comprehensive project demonstrating modern vanilla JavaScript DOM manipulation techniques

πŸ“‹ Project Overview

This assignment showcases advanced DOM manipulation skills through two interactive web applications built with vanilla JavaScript, HTML, and CSS. The project emphasizes modern web development practices including event delegation, debouncing, local storage persistence, and real-time user interactions.

πŸš€ Live Demo

Open the HTML files directly in your browser to see the applications in action:

  • Contact Form: Open contact-form/index.html
  • Todo App: Open todo-app/index.html

πŸ“ Project Structure

advanced-dom-javascript-assignment/
β”œβ”€β”€ contact-form/
β”‚   β”œβ”€β”€ index.html          # Contact form HTML structure
β”‚   β”œβ”€β”€ style.css           # Modern CSS styling with animations
β”‚   └── script.js           # Contact form JavaScript logic
β”œβ”€β”€ todo-app/
β”‚   β”œβ”€β”€ index.html          # Todo application HTML structure
β”‚   β”œβ”€β”€ style.css           # Responsive CSS with modern design
β”‚   └── script.js           # Todo app JavaScript functionality
└── README.md               # Project documentation

✨ Features Overview

πŸ“§ Smart Contact Form

  • Real-time Validation: Instant feedback as users type
  • Debounced Input: Validates after 300ms delay to improve performance
  • Message History: Persistent storage of submitted messages
  • Event Delegation: Efficient event handling for dynamic delete buttons
  • Local Storage: Messages survive browser refresh
  • Responsive Design: Mobile-friendly interface

βœ… Dynamic Todo List

  • CRUD Operations: Create, Read, Update, Delete todos
  • Debounced Search: Live search with 400ms delay
  • Smart Filtering: Filter by All, Active, or Completed todos
  • Local Storage: Persistent todo storage
  • Event Delegation: Single event listener handles all todo interactions
  • Real-time Stats: Live counter of total and completed todos

πŸ›  Technical Implementation

Core Technologies

  • HTML5: Semantic markup with proper form elements
  • CSS3: Modern styling with Flexbox, animations, and responsive design
  • Vanilla JavaScript: ES6+ features with class-based architecture

Key Programming Concepts

1. Event Delegation

// Single event listener handles multiple dynamic elements
this.messageHistory.addEventListener('click', (e) => {
    if (e.target.classList.contains('delete-btn')) {
        const messageId = e.target.dataset.messageId;
        this.deleteMessage(messageId);
    }
});

2. Debouncing Technique

debouncedValidate(fieldName, delay) {
    if (this.debounceTimers[fieldName]) {
        clearTimeout(this.debounceTimers[fieldName]);
    }
    
    this.debounceTimers[fieldName] = setTimeout(() => {
        this.validateField(fieldName);
        this.updateSubmitButton();
    }, delay);
}

3. Local Storage with Error Handling

saveMessage(message) {
    try {
        let messages = this.getMessagesFromStorage();
        messages.unshift(message);
        localStorage.setItem('contactMessages', JSON.stringify(messages));
    } catch (error) {
        console.error('Error saving message to localStorage:', error);
        alert('Failed to save message. Please try again.');
    }
}

4. Real-time Validation

validateField(fieldName) {
    const field = document.getElementById(fieldName);
    const errorElement = document.getElementById(`${fieldName}Error`);
    let isValid = false;
    let errorMessage = '';
    
    // Field-specific validation logic
    // Updates UI immediately with visual feedback
}

πŸ“Š Data Structures

Contact Message Object

{
    id: 1642123456789,                    // Unique timestamp ID
    name: "John Doe",                     // User's name (min 2 chars)
    email: "john@email.com",              // Valid email format
    message: "Hello, this is a test...",  // Message text (min 10 chars)
    timestamp: "2024-01-15T10:30:00.000Z" // ISO timestamp
}

Todo Item Object

{
    id: 1642123456789,                    // Unique timestamp ID
    text: "Learn JavaScript DOM",         // Todo text (max 200 chars)
    completed: false,                     // Completion status
    createdAt: "2024-01-15T10:30:00.000Z" // ISO timestamp
}

🎨 UI/UX Features

Visual Design

  • Modern Gradient Backgrounds: Eye-catching color schemes
  • Smooth Animations: CSS transitions and keyframe animations
  • Interactive Feedback: Hover effects and state changes
  • Responsive Layout: Mobile-first design approach

User Experience

  • Real-time Feedback: Instant validation and error messages
  • Loading States: Visual feedback during operations
  • Empty States: Helpful messages when no data exists
  • Accessibility: Proper labels and keyboard navigation

Performance Optimizations

  • Debounced Inputs: Reduces unnecessary API calls and validations
  • Event Delegation: Minimizes event listeners for better performance
  • Efficient DOM Updates: Strategic use of innerHTML vs createElement
  • Lazy State Updates: Only re-render when necessary

πŸ”§ Installation & Usage

Getting Started

  1. Clone or download this repository
  2. Open the project folder in your preferred code editor
  3. Launch the applications:
    • Contact Form: Open contact-form/index.html in your browser
    • Todo App: Open todo-app/index.html in your browser

No Build Process Required

  • βœ… Pure vanilla JavaScript - no frameworks or build tools
  • βœ… Self-contained applications with inline dependencies
  • βœ… Works in any modern browser (Chrome, Firefox, Safari, Edge)

Browser Compatibility

  • Modern Browsers: Full support for Chrome 60+, Firefox 55+, Safari 11+, Edge 79+
  • JavaScript Features: ES6+ classes, arrow functions, template literals
  • CSS Features: Flexbox, CSS Grid, CSS Custom Properties

πŸ“± Responsive Design

Both applications are fully responsive and optimized for:

  • Desktop: Full-featured layout with optimal spacing
  • Tablet: Adapted layout with touch-friendly interactions
  • Mobile: Stacked design with simplified navigation

Breakpoints

  • Large screens: 1200px and above
  • Medium screens: 768px to 1199px
  • Small screens: 480px to 767px
  • Extra small: Below 480px

πŸ§ͺ Testing Scenarios

Contact Form Testing

  1. Validation Testing:

    • Enter invalid email formats
    • Try names shorter than 2 characters
    • Submit messages shorter than 10 characters
    • Test real-time validation timing
  2. Functionality Testing:

    • Submit valid forms and check message history
    • Refresh page and verify persistence
    • Delete messages and confirm removal
    • Test form reset after submission

Todo App Testing

  1. CRUD Operations:

    • Add new todos with various lengths
    • Mark todos as complete/incomplete
    • Delete todos and verify removal
    • Test empty input handling
  2. Search & Filter Testing:

    • Search for partial text matches
    • Test filter combinations (All/Active/Completed)
    • Verify search debouncing behavior
    • Test edge cases (no results, empty todos)

πŸ”’ Error Handling

Robust Error Management

  • localStorage Failures: Graceful degradation when storage is unavailable
  • Invalid Data: Validation and sanitization of user inputs
  • Browser Compatibility: Fallbacks for older browser features
  • User Feedback: Clear error messages and recovery suggestions

Input Sanitization

  • XSS Prevention: HTML escaping for user-generated content
  • Data Validation: Client-side validation with server-side mindset
  • Type Checking: Runtime validation of data structures

πŸš€ Advanced Features

Performance Features

  • Debounced Search: 400ms delay prevents excessive filtering
  • Debounced Validation: 300ms delay improves user experience
  • Efficient Re-rendering: Minimal DOM manipulation
  • Event Optimization: Single event listeners with delegation

User Experience Enhancements

  • Smart Date Formatting: Relative timestamps (2h ago, Yesterday)
  • Visual State Management: Loading states and transitions
  • Keyboard Accessibility: Enter key support for form submission
  • Touch-Friendly: Optimized for mobile interactions

Data Management

  • Persistent Storage: Automatic save/load with localStorage
  • Data Integrity: Validation and cleanup of stored data
  • Backup Handling: Error recovery for corrupted data

πŸ“ˆ Learning Outcomes

This project demonstrates proficiency in:

Core JavaScript Concepts

  • βœ… DOM Manipulation: Dynamic element creation and modification
  • βœ… Event Handling: Modern event patterns and delegation
  • βœ… Async Programming: Timers and debouncing techniques
  • βœ… Data Structures: Object manipulation and array methods
  • βœ… Error Handling: Try-catch blocks and graceful degradation

Modern Web Development

  • βœ… Responsive Design: Mobile-first CSS approaches
  • βœ… User Experience: Interactive feedback and state management
  • βœ… Performance: Optimization techniques and best practices
  • βœ… Accessibility: Semantic HTML and keyboard navigation
  • βœ… Code Organization: Class-based architecture and separation of concerns

Professional Skills

  • βœ… Code Quality: Clean, maintainable, and documented code
  • βœ… Testing Mindset: Edge case handling and user scenario coverage
  • βœ… Problem Solving: Creative solutions to common web challenges
  • βœ… Best Practices: Industry-standard patterns and conventions

🀝 Contributing

Feel free to fork this project and submit pull requests for improvements:

  • Bug Fixes: Report and fix any issues you encounter
  • Feature Enhancements: Add new functionality or improve existing features
  • Code Improvements: Optimize performance or code organization
  • Documentation: Enhance comments and documentation

πŸ“„ License

This project is open source and available under the MIT License.

πŸ‘¨β€πŸ’» Author

Created as part of an advanced DOM & JavaScript assignment to demonstrate modern vanilla JavaScript development techniques.


Happy Coding! πŸŽ‰

This project showcases the power of vanilla JavaScript and modern web development practices without relying on external frameworks or libraries.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published