-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9-36. Form Events.js
More file actions
60 lines (44 loc) · 1.59 KB
/
9-36. Form Events.js
File metadata and controls
60 lines (44 loc) · 1.59 KB
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
// Example code (Here i am not uploading HTML and CSS file to Github of this code)
/* Form Events :
- change : The change event is triggered when the content of an input field
is changed or when the user selects a value from the dropdown etc.
- focus : The focus event is triggered when the input field is focused by the user.
- blur : The blur event is triggered when the input field loses focus.
- submit : The submit event is triggered when the submit button is clicked by the user
*/
console.clear()
// - change :
var username = document.getElementById('username');
username.addEventListener('change',function(){
console.log('Value Changed');
});
// another event listener : "input"
var username = document.getElementById('username');
username.addEventListener('input',function(){
console.log('Value Changed');
});
// for uppercase :
var username = document.getElementById('username');
username.addEventListener('input',function(event){
var currentValue = event.target.value;
currentValue = currentValue.toUpperCase();
console.log(currentValue);
});
// - focus :
username.addEventListener('focus', function(){
console.log('Element Fcussed');
});
// - blur :
username.addEventListener('blur', function(){
console.log('Element Lost Focus');
});
// - submit :
var loginForm = document.getElementById('login-form');
loginForm.addEventListener('submit', function(){
alert('Submit Button Clicked')
});
// or
loginForm.addEventListener('submit', function(){
alert('Submit Button Clicked')
e.preventDefault();
});