-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path48 Interactions in JS.html
84 lines (77 loc) · 3.5 KB
/
48 Interactions in JS.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
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
<html lang="en">
<head>
<title>JavaScript interaction:alert,prompt,confirm box</title>
</head>
<body>
<!-- JavaScript has three kind of popup boxes: Alert box, Confirm box, and Prompt box.
Alert Box:
An alert box is often used if you want to make sure information comes through to the user.
When an alert box pops up, the user will have to click "OK" to proceed.
Syntax:
window.alert("sometext");
The window.alert() method can be written without the window prefix.
i.e: alert("sometext");
Confirm Box:
A confirm box is often used if you want the user to verify or accept something.
When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed.
If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false.
Syntax:
window.confirm("sometext");
The window.confirm() method can be written without the window prefix.
i.e: confirm("sometext");
Prompt Box:
A prompt box is often used if you want the user to input a value before entering a page.
When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value.
If the user clicks "OK" the box returns the input value. If the user clicks "Cancel" the box returns null.
Syntax:
window.prompt("sometext","defaultText");
The window.prompt() method can be written without the window prefix.
i.e : prompt("sometext","defaultText");
-->
<button id="alert-btn">Alert box</button>
<button onclick="userClicks()">confirm box</button>
<p id="text-box-confirm"></p>
<button onclick="functionPrompt()">prompt box</button>
<p id="text-box-promt"></p>
<script>
document.getElementById("alert-btn").onclick=function(){
alert("I am an alert box");
}
function userClicks(){
var userRespond;
if(confirm("Press a button!")){
userRespond="You Pressed Ok!"
}
else{
userRespond="You Pressed Cancel";
}
document.getElementById("text-box-confirm").innerHTML=userRespond;
}
function functionPrompt(){
let userText;
let user=prompt("Enter You Enroll Number for Entry!","eg:1234"); // providing default value here is optional
// or let user=prompt("Enter You Enroll Number for Entry!");
if(user==null || user==''){
userText="You didn't provided your enroll number";
}
else{
userText="Thanku: "+user+" Please Enter Your Class Room!";
}
document.getElementById("text-box-promt").innerHTML=userText;
}
//Line Breaks
// To display line breaks inside a popup box, use a back-slash followed by the character n.
// i.e \n
// Example
alert("Hello\nHow are you?");
var response=prompt("Enter Id?")
let id="#6655";
if(response == id){
alert("Please Enter");
}
else{
alert("Wrong Id!");
}
</script>
</body>
</html>