Unversion parameters.js
[vchess.git] / client / client_OLD / javascripts / contactForm.js
1 // Note: not using Vue, but would be possible
2 function trySendMessage()
3 {
4 let email = document.getElementById("userEmail");
5 let subject = document.getElementById("mailSubject");
6 let content = document.getElementById("mailContent");
7 const error = checkNameEmail({email: email});
8 if (!!error)
9 return alert(error);
10 if (content.value.trim().length == 0)
11 return alert("Empty message");
12 if (subject.value.trim().length == 0 && !confirm("No subject. Send anyway?"))
13 return;
14
15 // Message sending:
16 ajax(
17 "/messages",
18 "POST",
19 {
20 email: email.value,
21 subject: subject.value,
22 content: content.value,
23 },
24 () => {
25 subject.value = "";
26 content.value = "";
27 let emailSent = document.getElementById("emailSent");
28 emailSent.style.display = "inline-block";
29 setTimeout(() => { emailSent.style.display = "none"; }, 2000);
30 }
31 );
32 }