I am currently working on creating a pop-up box that, when triggered (with a delay), will showcase a counter displaying the number of clicks along with the dates of each click!
I would like to present this information in a structured table format within a cell, similar to the following example:
Clicks Time 1 Thursday 4, 2018 2 Monday 3, 2018
Below is the snippet of my HTML code implementation:
function DisplayMessage() {
document.getElementById('myText').innerHTML = 'Hey <strong>Thanks!</strong>';
}
var clickCounter = 1;
var popupElement = document.getElementById("popup");
var inputField = document.getElementById("popup-delay");
var displayButton = document.getElementById("popup-show");
var closeButton = document.getElementById("popup-close");
displayButton.addEventListener("click", function onClickToShow() {
var userInput = parseInt(inputField.value, 10);
if (isNaN(userInput)) {
alert("NaN (Not A Number) !");
}
else {
var timeDelay = userInput * 1000;
displayButton.removeEventListener("click", onClickToShow);
document.getElementById("num1").innerHTML = clickCounter;
clickCounter = clickCounter + 1;
document.getElementById("num4").innerHTML += "<span>" + Date() + "</span>";
setTimeout(function() {
popupElement.style.display = "block";
closeButton.addEventListener("click", function onCloseClicked() {
closeButton.removeEventListener("click", onCloseClicked);
displayButton.addEventListener("click", onClickToShow);
popupElement.style.display = "none";
});
}, timeDelay);
}
});
#popup {
display: none;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: yellow;
padding: 1em;
}
#thecounter {
float: right;
background-color: rebeccapurple;
padding-top: 50px;
padding-bottom: 50px;
width: 10%;
margin-right: 10px;
font-size: 30px;
color: white;
text-align: center;
}
#thetime {
float: right;
background-color: rosybrown;
padding-top: 50px;
padding-bottom: 50px;
width: 10%;
font-size: 30px;
color: white;
text-align: center;
}
#num4 span {
font-size: 20px;
display: block;
margin-bottom: 4px;
padding: 4px;
}
Delay: <input type="text" id="popup-delay" /> <button type="button" id="popup-show">Show</button>
<div id="popup">
<p>I am a popup :-)</p>
<button type="button" id="popup-close">Close</button>
</div>
<div id="container">
<div id="thecounter">
<p id="num2">clicks </p>
<p id="num1">0 </p>
</div>
<div id="thetime">
<p id="num3">time </p>
<p id="num4"> </p>
</div>
</div>