mne-nuzhno-sayt-priglatelnuy/script.js

56 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

document.addEventListener('DOMContentLoaded', function() {
const form = document.getElementById('registrationForm');
const successMessage = document.getElementById('successMessage');
form.addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(form);
const data = {
firstName: formData.get('firstName'),
lastName: formData.get('lastName'),
company: formData.get('company'),
position: formData.get('position'),
email: formData.get('email'),
phone: formData.get('phone'),
country: formData.get('country'),
dietary: formData.get('dietary')
};
console.log('Заявка на участие:', data);
form.style.display = 'none';
successMessage.style.display = 'block';
setTimeout(() => {
alert('Спасибо за подтверждение участия!\n\nВаша заявка:\n' +
data.firstName + ' ' + data.lastName + '\n' +
data.company + ' — ' + data.position + '\n' +
data.email + '\n' +
data.phone + '\n' +
'Страна: ' + data.country + '\n\n' +
'Мы свяжемся с вами для уточнения деталей.');
}, 500);
});
const phoneInput = document.getElementById('phone');
phoneInput.addEventListener('input', function(e) {
let x = e.target.value.replace(/\D/g, '').match(/(\d{0,1})(\d{0,3})(\d{0,3})(\d{0,2})(\d{0,2})/);
if (!x[2]) {
e.target.value = x[1] ? '+' + x[1] : '';
} else {
e.target.value = !x[3] ? '+7 (' + x[2] : '+7 (' + x[2] + ') ' + x[3] + (x[4] ? '-' + x[4] : '') + (x[5] ? '-' + x[5] : '');
}
});
const inputs = form.querySelectorAll('input, select, textarea');
inputs.forEach(input => {
input.addEventListener('focus', function() {
this.parentElement.classList.add('focused');
});
input.addEventListener('blur', function() {
this.parentElement.classList.remove('focused');
});
});
});