w/raw pre-uploader
This commit is contained in:
@@ -1,48 +1,87 @@
|
||||
const textTaoL = document.getElementById('linkItem');
|
||||
const bttn = document.getElementById('bt');
|
||||
const linkTaoL = document.getElementById('linkTao');
|
||||
const emal = document.getElementById('email');
|
||||
const uploader = document.getElementById('uploader');
|
||||
|
||||
var inUnder = document.getElementById('inUnderline')
|
||||
var emailUnderline = document.getElementById('emailUnderline')
|
||||
|
||||
|
||||
// function change(){
|
||||
// if (document.getElementById('radio1').checked && document.getElementById('radio2').checked == false){
|
||||
// linkTao.style.display = 'block';
|
||||
// textTao.style.display = 'none';
|
||||
// console.log(1)
|
||||
// }
|
||||
// else if (document.getElementById('radio1').checked == false && document.getElementById('radio2').checked){
|
||||
// textTao.style.display = 'block';
|
||||
// linkTao.style.display = 'none';
|
||||
// console.log(2)
|
||||
// }
|
||||
// else{
|
||||
// textTao.style.display = 'none';
|
||||
// linkTao.style.display = 'none';
|
||||
// console.log(3)
|
||||
// }
|
||||
// }
|
||||
window.onload = function () {
|
||||
textTaoL.value = "";
|
||||
linkTaoL.value = "";
|
||||
emal.value = "";
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const radio1 = document.getElementById('radio1');
|
||||
const radio2 = document.getElementById('radio2');
|
||||
const linkTao = document.getElementById('inputLink');
|
||||
const textTao = document.getElementById('inputText');
|
||||
|
||||
function toggleInputs() {
|
||||
if (radio1.checked) {
|
||||
linkTao.style.display = 'flex';
|
||||
textTao.style.display = 'none';
|
||||
console.log(1);
|
||||
} else if (radio2.checked && radio1.checked == false) {
|
||||
linkTao.style.display = 'none';
|
||||
textTao.style.display = 'flex';
|
||||
console.log(2);
|
||||
} else {
|
||||
linkTao.style.display = 'none';
|
||||
textTao.style.display = 'none';
|
||||
console.log(3);
|
||||
emal.addEventListener("change", function () {
|
||||
bttn.disabled = false;
|
||||
emailUnderline.textContent = '';
|
||||
|
||||
var emailRe = /\S+@\S+\.\S+/;
|
||||
var isValid = emailRe.test(emal.value);
|
||||
|
||||
if (!isValid) {
|
||||
emailUnderline.textContent = '*Введите корректный адрес электронной почты.';
|
||||
bttn.disabled = true;
|
||||
}
|
||||
else {
|
||||
bttn.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const inputs = document.querySelectorAll('.inpt2');
|
||||
inputs.forEach(input => {
|
||||
input.addEventListener("change", function () {
|
||||
inUnder.textContent = '';
|
||||
if (linkTaoL.value === "" && textTaoL.value === "") {
|
||||
inUnder.textContent = '*Введите ссылку или текстовое описание желаемого товара.';
|
||||
bttn.disabled = true;
|
||||
}
|
||||
else {
|
||||
bttn.disabled = false;
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
document.getElementById('form').addEventListener("submit", function (event) {
|
||||
bttn.disabled = false;
|
||||
|
||||
|
||||
if (emal.value != '' && (textTaoL.value == '' || linkTaoL.value == '')) {
|
||||
event.preventDefault();
|
||||
uploader.style.display = "block";
|
||||
|
||||
const ToSend = { 'email': emal.value.toString(), 'link': linkTaoL.value, 'text': textTaoL.value };
|
||||
event.preventDefault();
|
||||
try {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/sendedData', true);
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
|
||||
xhr.onload = function () {
|
||||
if (xhr.status === 200) {
|
||||
const response = JSON.parse(xhr.responseText);
|
||||
console.log("Получено спустя 5 секунд:", response.status);
|
||||
event.preventDefault();
|
||||
|
||||
const timeoutId = setTimeout(() => {
|
||||
window.location.href = "OK";
|
||||
window.location.replace = "OK";
|
||||
}, 5000);
|
||||
}
|
||||
};
|
||||
|
||||
console.log("Данные отправлены. Ждем ответа сервера...");
|
||||
xhr.send(JSON.stringify(ToSend));
|
||||
}
|
||||
catch (Error) {
|
||||
console.log(Error)
|
||||
}
|
||||
}
|
||||
|
||||
linkTao.style.display = 'none';
|
||||
textTao.style.display = 'none';
|
||||
|
||||
radio1.addEventListener('click', toggleInputs);
|
||||
radio2.addEventListener('click', toggleInputs);
|
||||
});
|
||||
Reference in New Issue
Block a user