-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
30 lines (23 loc) · 905 Bytes
/
Copy pathapp.js
File metadata and controls
30 lines (23 loc) · 905 Bytes
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
const inputElement = document.querySelector('#product-name');
const countNumber = document.querySelector('#remaining-chars');
const maxAllowedChars = inputElement.maxLength;
function count(event) {
const string = event.target.value;
const stringLength = string.length;
const remainingChars = maxAllowedChars - stringLength;
countNumber.textContent = remainingChars;
if (remainingChars===0){
inputElement.classList.add('error');
countNumber.classList.add('error');
}
else if(remainingChars<=10){
inputElement.classList.remove('error');
countNumber.classList.remove('error');
inputElement.classList.add('warning');
countNumber.classList.add('warning');
} else {
inputElement.classList.remove('warning');
countNumber.classList.remove('warning');
}
}
inputElement.addEventListener('input', count);