I have a JavaScript function that controls the display of a popup window based on its visibility. The function used to work perfectly, with the close button effectively hiding the window when clicked. However, after making some changes to the code, the close button no longer functions as intended. I have included both the previous and current versions of the function, along with the 'overlay' div it interacts with and the CSS styles for the div. Any assistance in identifying what went wrong and how to fix it would be highly appreciated. I am struggling to pinpoint the exact cause of the issue.
Previous (working) function:
<script>
function overlay(descrip, name) {
var descripBox = "<div><h3>"+name+"</h3><p>"+ descrip +"</p></br><input type='button' onclick='overlay()' value='Close'></input></div>";
var el = document.getElementById("overlay");
el.innerHTML = descripBox;
el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}
</script>
Current (not working) function:
<script>
function overlay(descrip, name, req) {
if(req != ''){
var obj = new Array();
obj = req.split("|");
var reqHtml = "Requirements:</br><ul>";
for(var i = 0; i < obj.length; i++)
{
reqHtml += "<li>"+obj[i]+"</li>";
}
reqHtml+= "</ul></br>";
}
else
var reqHtml = '';
var descripBox = "<div><h3>"+name+"</h3><p>"+ descrip +"</p></br>"+
reqHtml +"<center><input type='button' onclick='overlay()' value='Close'></input></center></div>";
var el = document.getElementById("overlay");
el.innerHTML = descripBox;
el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}
</script>
Overlay div:
<div id="overlay">
<div>
</br>
<input type="button" onclick="overlay()" value="Close"></input>
</div>
</div>
CSS:
#overlay {
visibility: hidden;
position: absolute;
left: 0px;
top: 500px;
width:100%;
height:100%;
z-index: 1000;
}
#overlay div {
width:300px;
margin: 100px auto;
background-color: #ebebeb;
border:2px solid #c7c7c7;
padding:15px;
}