Untitled

mail@pastecode.io avatar
unknown
plain_text
4 months ago
1.7 kB
1
Indexable
// Carousel Functionality
let currentSlide = 0;
const slides = document.querySelectorAll(".slide");

function showSlide(slideIndex) {
    slides.forEach((slide, index) => {
        slide.style.display = (index === slideIndex) ? "block" : "none";
    });
}

function nextSlide() {
    currentSlide = (currentSlide + 1) % slides.length;
    showSlide(currentSlide);
}

function prevSlide() {
    currentSlide = (currentSlide - 1 + slides.length) % slides.length;
    showSlide(currentSlide);
}

// Initialize the first slide
showSlide(currentSlide);

// Custom Validation for Registration Form
document.addEventListener('DOMContentLoaded', function () {
    const registrationForm = document.getElementById('registrationForm');
    if (registrationForm) {
        registrationForm.addEventListener('submit', function (e) {
            e.preventDefault();
            const username = document.getElementById('username').value.trim();
            const email = document.getElementById('email').value.trim();
            const password = document.getElementById('password').value.trim();
            const errorMessage = document.getElementById('error-message');

            // Simple validation checks
            if (username === '' || email === '' || password === '') {
                errorMessage.textContent = 'All fields are required.';
            } else if (password.length < 6) {
                errorMessage.textContent = 'Password must be at least 6 characters long.';
            } else {
                errorMessage.textContent = '';
                alert('Registration Successful!');
                registrationForm.reset();
            }
        });
    }
});
Leave a Comment