|
|
| |
| document.addEventListener('DOMContentLoaded', function() { |
| |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { |
| anchor.addEventListener('click', function(e) { |
| e.preventDefault(); |
| document.querySelector(this.getAttribute('href')).scrollIntoView({ |
| behavior: 'smooth' |
| }); |
| }); |
| }); |
|
|
| |
|
|
| |
| const validateForm = (form) => { |
| const inputs = form.querySelectorAll('input[required]'); |
| let isValid = true; |
| |
| inputs.forEach(input => { |
| if (!input.value.trim()) { |
| input.classList.add('border-red-500'); |
| isValid = false; |
| } else { |
| input.classList.remove('border-red-500'); |
| } |
| }); |
|
|
| |
| const email = form.querySelector('#email'); |
| if (email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.value)) { |
| email.classList.add('border-red-500'); |
| isValid = false; |
| } |
|
|
| |
| const password = form.querySelector('#password'); |
| if (password && password.value.length < 8) { |
| password.classList.add('border-red-500'); |
| isValid = false; |
| } |
|
|
| return isValid; |
| }; |
|
|
| |
| document.querySelectorAll('form').forEach(form => { |
| form.addEventListener('submit', function(e) { |
| if (!validateForm(this)) { |
| e.preventDefault(); |
| e.stopPropagation(); |
| } |
| }); |
|
|
| |
| form.querySelectorAll('input').forEach(input => { |
| input.addEventListener('input', function() { |
| this.classList.remove('border-red-500'); |
| }); |
| }); |
| }); |
| }); |
|
|