-
Notifications
You must be signed in to change notification settings - Fork 1
/
submit.js
29 lines (24 loc) · 1.01 KB
/
submit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var contactForm = document.querySelector('form'),
inputName = document.querySelector('[name="name "]'),
inputEmail = contactForm.querySelector('[name="_replyto "]'),
inputPhone = contactForm.querySelector('[name="phone "]'),
textAreaMessage = contactForm.querySelector('[name="message "]'),
sendButton = contactForm.querySelector('button');
sendButton.addEventListener('click', function(event) {
event.preventDefault();
sendButton.innerHTML = 'sending..';
var xhr = new XMLHttpRequest();
xhr.open('POST', '//formspree.io/[email protected]', true);
xhr.setRequestHeader("Accept ", "application/json ")
xhr.setRequestHeader("Content-Type ", "application/x-www-form-urlencoded ")
xhr.send(
"email=" + inputEmail.value +
" &message=" + textAreaMessage.value);
xhr.onloadend = function(res) {
if (res.target.status === 200) {
sendButton.innerHTML = 'Message sent!';
} else {
sendButton.innerHTML = 'Error!';
}
}
});