-
Notifications
You must be signed in to change notification settings - Fork 0
/
9.5_prac.html
43 lines (34 loc) · 1 KB
/
9.5_prac.html
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
<!DOCTYPE html>
<html>
<head>
<title>Practice DOM // for enter key </title>
</head>
<body>
<!-- step - 1 : onkeydown
step -2 : console the event.key
step -3 : check if the key is "Enter
-->
<h2>PRACTICE 3 // for enter key </h2>
<input type="text" placeholder="Enter name to verify" class="js-verify"
onkeydown="
event.key;// This is j-script build-in object which gives information what key is pressed
if(event.key === 'Enter'){
Practice3();
}
">
<button onclick="Practice3()">verify</button>
<p class="js-para2"></p>
<script>
function Practice3() { // and button3 does'nt need to convert to j-script
let paraElem2 = document.querySelector('.js-para2');
const verifyElem = document.querySelector('.js-verify').value; // input element does'nt need .innerHTML
if (verifyElem === 'Roshan') {
paraElem2.innerHTML = 'Person verified!';
}
else {
paraElem2.innerHTML = 'Invalid Username!';
}
}
</script>
</body>
</html>