Workplace Safety Compliance Checker

Workplace Safety Compliance Checker

Assess your workplace against common U.S. safety standards. This is a general guide, not a substitute for a professional OSHA inspection.

Compliance Report

Compliance Score

0%

Identified Issues

0

Generate the report to see detailed findings and recommendations.

${q.text}

`).join(''); } } // --- TAB NAVIGATION --- function updateTabDisplay() { tabButtons.forEach(button => button.classList.toggle('active', parseInt(button.dataset.tab) === currentTab)); tabContents.forEach(content => content.style.display = 'none'); document.getElementById(`tab-content-${currentTab}`).style.display = 'block'; prevBtn.disabled = currentTab === 1; nextBtn.textContent = currentTab === totalTabs - 1 ? 'Generate Report' : 'Next'; if (currentTab === totalTabs) { nextBtn.style.display = 'none'; } else { nextBtn.style.display = 'inline-flex'; } } function changeTab(newTab) { if (newTab >= 1 && newTab <= totalTabs) { if (newTab === totalTabs && currentTab === totalTabs - 1) { if(form.checkValidity()){ generateReport(); } else { form.reportValidity(); return; // Don't proceed if form is invalid } } currentTab = newTab; updateTabDisplay(); } } // --- REPORT & PDF LOGIC --- function generateReport() { const formData = new FormData(form); let yesCount = 0; let noCount = 0; let naCount = 0; const issues = []; for (const q of questionsDB) { const answer = formData.get(q.id); if (answer === 'yes') yesCount++; else if (answer === 'no') { noCount++; issues.push(q); } else if (answer === 'na') naCount++; } const totalApplicable = questionsDB.length - naCount; const score = totalApplicable > 0 ? Math.round((yesCount / totalApplicable) * 100) : 100; // Update UI document.getElementById('compliance-score').textContent = `${score}%`; document.getElementById('issues-found').textContent = noCount; const detailsContainer = document.getElementById('report-details'); if (issues.length > 0) { detailsContainer.innerHTML = `

Areas for Improvement:

    ${issues.map(issue => `
  • Issue: ${issue.text}
    Recommendation: ${issue.recommendation}
  • `).join('')}
`; } else { detailsContainer.innerHTML = `

Excellent! No compliance issues were found based on your answers.

`; } document.getElementById('downloadPdfBtn').disabled = false; } async function handlePdfDownload() { const formData = new FormData(form); const reportData = questionsDB.map(q => ({...q, answer: formData.get(q.id)})); const scoreEl = document.getElementById('compliance-score').textContent; const issuesEl = document.getElementById('issues-found').textContent; const contentHTML = `

Workplace Safety Compliance Report

Report generated on ${new Date().toLocaleDateString('en-US')}

Compliance Score

${scoreEl}

Identified Issues

${issuesEl}

Detailed Findings & Recommendations

${[1, 2, 3, 4].map(tabNum => { const tabName = document.querySelector(`.tab-button[data-tab="${tabNum}"]`).textContent; return `

${tabName}

${reportData.filter(q => q.tab === tabNum).map(q => ` `).join('')}
QuestionStatus
${q.text} ${q.answer === 'no' ? `

Recommendation: ${q.recommendation}

` : ''}
${q.answer.toUpperCase()}
`; }).join('')} `; document.getElementById('pdf-content').innerHTML = contentHTML; const { jsPDF } = window.jspdf; const button = document.getElementById('downloadPdfBtn'); button.textContent = 'Generating...'; button.disabled = true; const pdfContainer = document.getElementById('pdf-container'); pdfContainer.classList.remove('invisible'); try { const canvas = await html2canvas(pdfContainer, { scale: 2 }); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const imgProps = pdf.getImageProperties(imgData); const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width; let heightLeft = pdfHeight; let position = 0; pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight); heightLeft -= pdf.internal.pageSize.getHeight(); while (heightLeft > 0) { position -= pdf.internal.pageSize.getHeight(); pdf.addPage(); pdf.addImage(imgData, 'PNG', 0, position, pdfWidth, pdfHeight); heightLeft -= pdf.internal.pageSize.getHeight(); } pdf.save('Workplace_Safety_Report.pdf'); } catch (error) { console.error("PDF generation failed:", error); } finally { button.textContent = 'Download Report as PDF'; button.disabled = false; pdfContainer.classList.add('invisible'); } } // --- INITIALIZATION --- renderQuestions(); updateTabDisplay(); nextBtn.addEventListener('click', () => changeTab(currentTab + 1)); prevBtn.addEventListener('click', () => changeTab(currentTab - 1)); document.getElementById('downloadPdfBtn').addEventListener('click', handlePdfDownload); tabButtons.forEach(button => { button.addEventListener('click', (e) => { const targetTab = parseInt(e.target.dataset.tab); // Allow navigation to report tab only if form is valid or already on a tab >= report tab if (targetTab === totalTabs && currentTab < totalTabs && !form.checkValidity()) { form.reportValidity(); } else { changeTab(targetTab); } }); }); });
Scroll to Top