complete form with AID

by jimkennelly

HTML

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<div class="container">
    <h2 class="mt-4">Incident Report Form</h2>
    
    <!-- Progress Bar -->
    <div class="progress mb-4">
        <div id="progressBar" class="progress-bar" role="progressbar" style="width: 20%;" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100">Step 1 of 5</div>
    </div>

    <form id="incidentReportForm">
        <!-- Page 1: People Involved -->
        <div class="page active" id="page1">
            <h3>Employee Information</h3>
            <div class="form-group">
                <label for="firstName">First Name</label>
                <input type="text" class="form-control" id="firstName" required>
            </div>
            <div class="form-group">
                <label for="lastName">Last Name</label>
                <input type="text" class="form-control" id="lastName" required>
            </div>
            <div class="form-group">
                <label for="department">Department Assigned</label>
                <input type="text" class="form-control" id="department" required>
            </div>
            <div class="form-group">
                <label for="title">Title</label>
                <input type="text" class="form-control" id="title" required>
            </div>
            <button type="button" class="btn btn-primary" onclick="nextPage(1)">Next</button>
        </div>

        <!-- Page 2: Person Completing Report -->
        <div class="page" id="page2">
            <h3>Report Completion</h3>
            <div class="form-group">
                <label for="reporterName">Name of Person Completing the Report</label>
               ...

CSS

.page {
            display: none;
        }
        .active {
            display: block;
        }
        .hidden {
            display: none;
        }

JavaScript

let currentPage = 1;
    
    nextPage(1);
    nextPage(2);
    nextPage(3);


function updateProgress() {
        const progressBar = document.getElementById('progressBar');
        const progressPercentage = (currentPage / 5) * 100;
        progressBar.style.width = `${progressPercentage}%`;
        progressBar.setAttribute('aria-valuenow', progressPercentage);
        progressBar.innerText = `Step ${currentPage} of 5`;
    }

    function nextPage(page) {
        document.getElementById(`page${page}`).classList.remove('active');
        currentPage++;
        document.getElementById(`page${currentPage}`).classList.add('active');
        updateProgress();
    }

    function prevPage(page) {
        document.getElementById(`page${page}`).classList.remove('active');
        currentPage--;
        document.getElementById(`page${currentPage}`).classList.add('active');
        updateProgress();
    }

    function showIncidentDetails() {
        const incidentType = document.getElementById('incidentType').value;
        const detailsDiv = document.getElementById('incidentDetails');
        detailsDiv.innerHTML = ''; // Clear previous content

			  //hide everything first
        $("#handled").hide();

				//show the group of form items that the user should see
        switch (incidentType) {
            case 'handled':
            	  $("#handled").show();
                break;
           	case 'struckAgainst':
                detailsDiv.innerHTML = `
                	 </div>
                    <div class="form-group">
                        <label for="struckAgainst">What did the employee walk into?</label>
                        <input type="text" class="form-control" id="struckAgainst">
                    </div>                  
                `;
                break;            
            case 'struckBy':
                detailsDiv.innerHTML = `
                	 </div>
                    <div class="form-group">
                        <label...