-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path09-keyboard--input-events.js
60 lines (50 loc) · 1.3 KB
/
09-keyboard--input-events.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* ******************************
* Keyboard & Input Events
* ******************************
**/
const form = document.querySelector('form');
const taskInput = document.getElementById('task');
const heading = document.querySelector('h5');
const select = document.querySelector('select');
// Clear input
taskInput.value = '';
// Form Button Submit
form.addEventListener('submit', runEvent);
/**
* ********************
* Keyboard Events
* ********************
**/
// Keydown
taskInput.addEventListener('keydown', runEvent);
// Keyup
taskInput.addEventListener('keyup', runEvent);
// Keypress
taskInput.addEventListener('keypress', runEvent);
// Focus
taskInput.addEventListener('focus', runEvent);
// Blur
taskInput.addEventListener('blur', runEvent);
// Cut
taskInput.addEventListener('cut', runEvent);
// Paste
taskInput.addEventListener('paste', runEvent);
// Input
taskInput.addEventListener('input', runEvent);
// Change Select List Option
select.addEventListener('change', runEvent);
/**
* ********************
* Event Handler (Function)
* ********************
**/
function runEvent(e) {
console.log(`EVENT TYPE: ${e.type}`);
// console.log(e.target.value);
// heading.innerText = e.target.value;
// Get input value
taskInput.value = ' ';
console.log(taskInput.value);
e.preventDefault();
}