Core Web Technologies: HTML Structures and JavaScript Interactivity

Essential HTML Semantic Elements

Building robust web pages begins with understanding structural tags. Below are fundamental components for organizing data.

Tabular Data Representation

Tables utilize specific hierarchical tags to organize row and column information effectively.

<table>
  <caption>Vehicle Fleet Registry</caption>
  <thead>
    <tr>
      <th>Identifier</th>
      <th>Details</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Row Data</td>
    </tr>
  </tbody>
</table>
  • colspan: Merges cells horizontally across multiple columns.
  • rowspan: Merges cells vertically across multiple rows.

Form Interactions

Collecting user input requires the <form> element configured with action URLs and submission methods (GET/POST).

<input type="text">       <!-- Standard text entry -->
<input type="password">   <!-- Masked character input -->
<input type="radio">      <!-- Mutually exclusive selection -->
<input type="checkbox">   <!-- Multiple choice selection -->
<textarea></textarea>     <!-- Multi-line text area -->
<select><option></select><!-- Dropdown menus -->

Buttons within forms control actions such as submission (submit) or clearing fields (reset). Every interactive form element should possess a distinct name attribute for data mapping.

JavaScript Runtime Environment

The JavaScript execution environment comprises three primary components working together to enable dynamic behavior.

Component Description
ECMAScript The standardized syntax and core language rules.
BOM (Browser Object Model) Interacts with the browser window outside the document content.
DOM (Document Object Model) API interfaces allowing manipulation of HTML/XML document structures.

Script Execution Strategy

To prevent blocking initial rendering, external scripts should ideally be placed at the end of the <body> tag or utilize the defer attribute.

<script src="./utils.js"></script>

Browser Object Models

window: Represents the global browser console context.
history: Manages session navigation records.

Method Functionality
back() Navigates to the previous URL in history stack.
forward() Moves forward to the next URL in history stack.
go(n) Jumps relative to current position based on integer argument.

location: Provides access to current page URL details including protocol, host, search parameters, and hash fragments.

Document Object Model (DOM)

The document object serves as the entry point to the content hierarchy.

  • Querying: Use getElementById(), querySelector(), or querySelectorAll() to retrieve node references.
  • Traversal: Access parent/child relationships via properties like parentElement, children, and nextElementSibling.
  • Manipulation: Dynamically altter content using createElement(), appendChild(), or remove().

Event-Driven Programming

Interactivity relies on detecting user actions through events attached to specific nodes.

Category Common Events
Window load, resize, scroll
Mouse click, mouseover, mouseenter
Keyboard keydown, keyup
Form focus, blur, submit, input

Modern best practices recommend using addEventListener() for attaching handlers rather than inline HTML attributes.

Practical Application: Dynamic Inventory Management

The following implemantation demonstrates a complete CRUD (Create, Read, Update, Delete) system using vanilla JavaScript and HTML tibles. This example manages a vehicle fleet inventory.


<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Fleet Management Dashboard</title>
</head>
<body>

    <section id="controls">
        <input type="text" id="search-input" placeholder="Search License Plate...">
        <button id="btn-search">Filter</button>
        <button id="btn-add">Add Vehicle</button>
        <select id="sort-select">
            <option value="default">Default Order</option>
            <option value="mileage-desc">High Mileage First</option>
            <option value="capacity-asc">Low Capacity First</option>
        </select>
        <button id="btn-sort">Sort</button>
    </section>

    <table id="fleet-table" border="1">
        <thead>
            <tr>
                <th>License Plate</th>
                <th>Odometer</th>
                <th>Capacity</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>

    <dialog id="entry-dialog">
        <h3>Record Details</h3>
        <form id="entry-form">
            <label>Plate:</label> <input name="plate" required>
            <label>Miles:</label> <input type="number" name="mileage">
            <label>Passengers:</label> <select name="capacity">
                <option value="5">5</option>
                <option value="7">7</option>
            </select>
            <button type="submit">Save Record</button>
            <button type="button" id="btn-close">Cancel</button>
        </form>
    </dialog>

    <script>
        // State management
        let inventory = [];
        
        // DOM References
        const tableBody = document.querySelector('#fleet-table tbody');
        const formDialog = document.getElementById('entry-dialog');
        const entryForm = document.getElementById('entry-form');
        
        // Render Logic
        const renderGrid = (dataSet) => {
            const rows = dataSet.map(item => 
                `<tr>
                    <td>${item.plate}</td>
                    <td>${item.mileage}</td>
                    <td>${item.capacity}</td>
                    <td>
                        <button class="act-edit" data-id="${item.id}">Edit</button>
                        <button class="act-delete" data-id="${item.id}">Remove</button>
                    </td>
                </tr>`
            ).join('');
            
            tableBody.innerHTML = rows || '<tr><td colspan="4">No Records Found</td></tr>';
            attachRowListeners();
        };

        // Event Delegation for Row Actions
        const attachRowListeners = () => {
            tableBody.addEventListener('click', (e) => {
                const target = e.target;
                const id = Number(target.dataset.id);

                if (target.classList.contains('act-delete')) {
                    inventory = inventory.filter(v => v.id !== id);
                    renderGrid(inventory);
                } else if (target.classList.contains('act-edit')) {
                    populateForm(inventory.find(v => v.id === id));
                    formDialog.showModal();
                }
            });
        };

        // Form Handling
        entryForm.addEventListener('submit', (e) => {
            e.preventDefault();
            const formData = new FormData(entryForm);
            const plateRegex = /^[A-Z0-9]{5}$/; // Simplified regex for demo
            
            if (!plateRegex.test(formData.get('plate'))) {
                alert('Invalid Plate Format');
                return;
            }

            const newEntry = {
                id: Date.now(),
                plate: formData.get('plate'),
                mileage: formData.get('mileage'),
                capacity: parseInt(formData.get('capacity'))
            };

            inventory.push(newEntry);
            renderGrid(inventory);
            formDialog.close();
            entryForm.reset();
        });

        // Sorting Logic
        document.getElementById('btn-sort').addEventListener('click', () => {
            const mode = document.getElementById('sort-select').value;
            if(mode === 'default') return renderGrid(inventory);
            
            const sortedList = [...inventory];
            if (mode === 'mileage-desc') {
                sortedList.sort((a,b) => b.mileage - a.mileage);
            }
            if (mode === 'capacity-asc') {
                sortedList.sort((a,b) => a.capacity - b.capacity);
            }
            renderGrid(sortedList);
        });

        // Initialization
        document.getElementById('btn-add').addEventListener('click', () => formDialog.showModal());
        document.getElementById('btn-close').addEventListener('click', () => formDialog.close());
        
        renderGrid([]);
    </script>
</body>
</html>

Posted on Sun, 31 May 2026 22:57:43 +0000 by lightningstrike