-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (40 loc) · 1.55 KB
/
index.js
File metadata and controls
48 lines (40 loc) · 1.55 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
// Get the modal
const modal = document.getElementById('modal');
// Get the button that opens the modal
const btn = document.getElementById("openModal");
// Get the <span> element that closes the modal
const span = document.getElementsByClassName("close")[0];
// When the user clicks on the button, open the modal
const inputText = document.querySelector("input[name='username']");
let text= document.createElement("p");
btn.onclick = function() {
modal.style.display = "block";
text.innerHTML=`Hey <strong>${inputText.value}</strong>, buckle up! You're officially logged in for Team Vibhav's epic Cloud Computing Workshop.
`
// Add a class to the paragraph element
text.classList.add("modal-text");
document.querySelector('.modal-content').appendChild(text);
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
// Function to handle explore button click
btn.addEventListener("click", function() {
// Check if the input text box has any value
if (inputText.value.trim() !== "") {
// If the input box is not empty, display the modal
modal.style.display = "block";
} else {
// If the input box is empty, show an alert message
alert("Please enter your name before exploring!");
modal.style.display = "none";
return;
}
});