Online Real-Time Interactive Polling System

Real-Time Interactive Polling System

Manage Live Poll

Participant Link (for sharing):

(This is a simulated link for demonstration)

Waiting for poll to start...

Results will appear here in real-time.

Create & Manage Poll Questions


Saved Questions

    Results will appear here in real-time.

    `; liveResultsContainer.innerHTML = ''; return; } const question = state.questions.find(q => q.id === state.activePoll.questionId); if (!question) return; liveResultsHeader.innerHTML = `

    ${question.text}

    `; liveResultsContainer.innerHTML = ''; question.options.forEach(option => { const votes = state.activePoll.results[option] || 0; const percentage = state.activePoll.totalVotes > 0 ? ((votes / state.activePoll.totalVotes) * 100).toFixed(1) : 0; const barDiv = document.createElement('div'); barDiv.innerHTML = `
    ${option} ${votes} votes (${percentage}%)
    `; liveResultsContainer.appendChild(barDiv); }); } // --- Event Handlers --- function bindEventListeners() { tabContainer.addEventListener('click', handleTabClick); addQuestionBtn.addEventListener('click', handleAddQuestion); startPollBtn.addEventListener('click', handleStartPoll); stopPollBtn.addEventListener('click', handleStopPoll); downloadPdfBtn.addEventListener('click', downloadPDF); document.getElementById('questionList').addEventListener('click', (e) => { if (e.target.closest('.delete-question-btn')) { const questionId = e.target.closest('.delete-question-btn').dataset.id; handleDeleteQuestion(parseInt(questionId)); } }); } function handleTabClick(e) { if (!e.target.matches('.tab-button')) return; document.querySelectorAll('.tab-button').forEach(btn => btn.classList.remove('active')); e.target.classList.add('active'); document.querySelectorAll('.tab-content').forEach(content => content.classList.remove('active')); document.getElementById(`${e.target.dataset.tab}Content`).classList.add('active'); } function handleAddQuestion() { const questionInput = document.getElementById('newQuestion'); const optionsInput = document.getElementById('newOptions'); const text = questionInput.value.trim(); const options = optionsInput.value.split(',').map(o => o.trim()).filter(o => o); if (text && options.length > 1) { state.questions.push({ id: Date.now(), text, options }); questionInput.value = ''; optionsInput.value = ''; saveState(); renderAll(); } else { alert('Please provide a question and at least two comma-separated options.'); } } function handleDeleteQuestion(id) { state.questions = state.questions.filter(q => q.id !== id); saveState(); renderAll(); } function handleStartPoll() { const questionId = parseInt(document.getElementById('pollQuestionSelector').value); if (!questionId) { alert('Please select a question to start.'); return; } const question = state.questions.find(q => q.id === questionId); // Reset and start state.activePoll = { isLive: true, questionId: questionId, results: Object.fromEntries(question.options.map(opt => [opt, 0])), totalVotes: 0, }; startPollBtn.disabled = true; stopPollBtn.disabled = false; downloadReportContainer.style.display = 'none'; // Simulate real-time votes state.pollInterval = setInterval(() => { const randomOption = question.options[Math.floor(Math.random() * question.options.length)]; state.activePoll.results[randomOption]++; state.activePoll.totalVotes++; renderLiveResults(); }, 1500); // New vote every 1.5 seconds renderLiveResults(); } function handleStopPoll() { clearInterval(state.pollInterval); state.activePoll.isLive = false; startPollBtn.disabled = false; stopPollBtn.disabled = true; if (state.activePoll.totalVotes > 0) { downloadReportContainer.style.display = 'block'; } } // --- PDF Generation --- function downloadPDF() { if (state.activePoll.totalVotes === 0) { alert("No results to download."); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF(); const question = state.questions.find(q => q.id === state.activePoll.questionId); doc.setFont('helvetica', 'bold'); doc.setFontSize(18); doc.text('Live Poll Final Report', 14, 22); doc.setFontSize(14); doc.text(question.text, 14, 35); const tableBody = Object.entries(state.activePoll.results).map(([option, votes]) => { const percentage = ((votes / state.activePoll.totalVotes) * 100).toFixed(1) + '%'; return [option, votes, percentage]; }); doc.autoTable({ startY: 45, head: [['Option', 'Vote Count', 'Percentage']], body: tableBody, headStyles: { fillColor: [37, 99, 235] } }); const finalY = doc.lastAutoTable.finalY; doc.setFontSize(12); doc.setFont('helvetica', 'bold'); doc.text(`Total Votes: ${state.activePoll.totalVotes}`, 14, finalY + 10); doc.save('Poll_Report.pdf'); } // --- Run on Load --- initialize(); });
    Scroll to Top