forked from AddalaGovindaRao/JavaScript_Development
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13_DOM_Events.html
More file actions
95 lines (84 loc) · 2.4 KB
/
13_DOM_Events.html
File metadata and controls
95 lines (84 loc) · 2.4 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JS DOM Events</title>
<style>
body{
font-family: "Comic Sans MS", sans-serif;
}
div{
background-color: lightgreen;
padding: 10px;
width: 400px;
}
input{
border: 2px solid lightgreen;
}
span{
color: red;
}
#results-div{
background-color: orangered;
color: white;
text-align: center;
}
</style>
</head>
<body>
<h2>JS Event Handling</h2>
<div>
<form>
<label>User Name </label>
<input type="text" id="username">
<span id="userText"></span>
<br>
<label>Password</label>
<input type="password" id="password"><span id="passText"></span>
<br>
<button type="button" onclick="getValues()">Get values</button>
</form>
</div>
<h2>JS Events Listeners</h2>
<div>
<form>
<label>Enter Text</label>
<input type="text" id="userInput">
</form>
</div>
<div id="results-div">
<h1 id="userInputText"></h1>
</div>
<script>
function getValues() {
var username = document.querySelector('#username').value;
var password = document.querySelector('#password').value;
if(username === 'naveen' && password === 'password'){
document.querySelector('#username').style.borderColor = 'green';
document.querySelector('#password').style.borderColor = 'green';
}
else{
document.querySelector('#username').style.borderColor = 'red';
document.querySelector('#password').style.borderColor = 'red';
document.querySelector('#userText').innerHTML = "UserName doesn't Exists";
}
}
// Event Listeners
// Get the Element
var userInput = document.querySelector('#userInput');
// Hookup an event
userInput.addEventListener('keyup',display);
// write function logic
function display() {
var userValue = userInput.value;
document.querySelector('#userInputText').innerHTML = userValue;
if(userValue === 'naveen'){
userInput.style.borderColor = 'green';
}
else{
userInput.style.borderColor = 'red';
}
}
</script>
</body>
</html>