Spaces:
Running
Running
File size: 3,230 Bytes
b420bfd a136712 b420bfd a136712 b420bfd a136712 b420bfd a136712 b420bfd a136712 b420bfd a136712 b420bfd a136712 b420bfd a136712 b420bfd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | document.addEventListener('DOMContentLoaded', function() {
// Initialize variables
let currentSection = 0;
const sections = document.querySelectorAll('.section');
const prevBtn = document.getElementById('prevBtn');
const nextBtn = document.getElementById('nextBtn');
const submitBtn = document.getElementById('submitBtn');
const progressBar = document.getElementById('progressBar');
// Show first section
showSection(currentSection);
// Next button click handler
nextBtn.addEventListener('click', function() {
if (currentSection < sections.length - 1) {
currentSection++;
showSection(currentSection);
updateProgressBar();
}
});
// Previous button click handler
prevBtn.addEventListener('click', function() {
if (currentSection > 0) {
currentSection--;
showSection(currentSection);
updateProgressBar();
}
});
// Function to show current section and hide others
function showSection(index) {
sections.forEach((section, i) => {
if (i === index) {
section.style.display = 'block';
section.classList.add('fade-in');
} else {
section.style.display = 'none';
}
});
// Update button visibility
if (index === 0) {
prevBtn.classList.add('hidden');
} else {
prevBtn.classList.remove('hidden');
}
if (index === sections.length - 1) {
nextBtn.classList.add('hidden');
submitBtn.classList.remove('hidden');
} else {
nextBtn.classList.remove('hidden');
submitBtn.classList.add('hidden');
}
}
// Update progress bar
function updateProgressBar() {
const progress = ((currentSection + 1) / sections.length) * 100;
progressBar.style.width = `${progress}%`;
}
// Form submission
document.getElementById('audienceForm').addEventListener('submit', function(e) {
e.preventDefault();
// Collect form data
const formData = new FormData(this);
const data = {};
formData.forEach((value, key) => {
if (!data[key]) {
data[key] = [];
}
data[key].push(value);
});
// Here you would typically send the data to a server
console.log('Collected data:', data);
// Show success message (in a real app, you would redirect or show results)
alert('Your audience criteria has been saved successfully!');
});
// Add toggle effect for checkboxes
const checkboxes = document.querySelectorAll('input[type="checkbox"]');
checkboxes.forEach(checkbox => {
checkbox.addEventListener('change', function() {
const label = this.nextElementSibling;
if (this.checked) {
label.classList.add('font-medium', 'text-emerald-800');
} else {
label.classList.remove('font-medium', 'text-emerald-800');
}
});
});
}); |