In my experience, I have completed two web-related classes that involved similar projects with popups using HTML and JavaScript. However, I am facing an issue where the popup either does not show at all or appears for only a brief moment before closing itself. While I cannot share the entire code here, below is a snippet of the problematic block (I included the script at the end of the file, outside the HTML tag):
<script type="text/javascript">
var popup = document.getElementById('popup');
var btn = document.getElementById('btn_popup');
var close = document.getElementById('close');
btn.onclick = function(){
popup.style.display = "block";
}
close.onclick = function(){
popup.style.display = "none";
}
</script>
I have borrowed these code segments from other pages where they worked perfectly fine, but on this page, they seem to be malfunctioning. I also utilize PHP to populate the dropdown list within the popup form. Interestingly, while the popup displays correctly on the previous page, here it flashes for a split second before disappearing.
Is there a solution to this problem? Any insights or clues would be greatly appreciated. Please refrain from suggesting frameworks (apart from w3, excluding w3 modals) to address this issue. I am currently using the latest version of Google Chrome to view these files, and have also tested them on Mozilla with the same outcome.