-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
23 lines (20 loc) · 818 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// JS for section #more form //
const subForm = document.querySelector('#subForm');
const email = document.querySelector('input[type="email"]');
const frequency = document.querySelector('#frequency');
subForm.addEventListener('submit', function(e){
e.preventDefault();
alert(`Thank you! You will receive our newsletter ${frequency.value} at ${email.value}`);
});
email.addEventListener('input', function() {
let emailInput = email.value;
email.style.backgroundColor = 'white';
for (let i = 0; i < emailInput.length; i++) {
if (emailInput[i] === '@') {
email.style.backgroundColor = 'green'; // only works when selecting the input type!
break;
} else if (emailInput[i] !== '@') {
email.style.backgroundColor = 'red';
email.style.color = 'white';
}}
})