I have a search where the results are displayed in a table generated by php on my main page. I want to display the results table in a popup/modal instead of on the page. Search works fine until I put it in the modal and then nothing pops up. I took the modal code from W3 schools. Any assistance or a better way to achieve this is much appreciated.
JavaScript
x
18
18
1
<div id="myModal" class="modal" name="officese">
2
<form action="" method="Post">
3
<label>Office Search:</label><br>
4
<input type="text" name="search" size="8">
5
<input id="popup" type="submit" name="submit">
6
</form>
7
<div class="modal-content">
8
<span class="close">×</span>
9
<?php
10
include 'testing.php';
11
$key=$_POST['search'];
12
if(isset($_POST['submit'])){
13
$new_search=dir_search($key);
14
}
15
?>
16
</div>
17
</div>
18
JS
JavaScript
1
17
17
1
<script>
2
var modal = document.getElementById("myModal";
3
var btn = document.getElementById("popup");
4
var span = document.getElementByClassName("close")[0];
5
btn.onclick = function(){
6
modal.style.display = "block";
7
}
8
span.onclick = function(){
9
modal.style.display = "none";
10
}
11
window.onclick = function(event){
12
if(event.target == modal){
13
modal.style.display = "none";
14
}
15
}
16
</script>
17
CSS:
JavaScript
1
37
37
1
.modal {
2
display: none; /* Hidden by default */
3
position: fixed; /* Stay in place */
4
z-index: 1; /* Sit on top */
5
left: 0;
6
top: 0;
7
width: 100%; /* Full width */
8
height: 100%; /* Full height */
9
overflow: auto; /* Enable scroll if needed */
10
background-color: rgb(0,0,0); /* Fallback color */
11
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
12
}
13
14
/* Modal Content/Box */
15
.modal-content {
16
background-color: #fefefe;
17
margin: 15% auto; /* 15% from the top and centered */
18
padding: 20px;
19
border: 1px solid #888;
20
width: 80%; /* Could be more or less, depending on screen size */
21
}
22
23
/* The Close Button */
24
.close {
25
color: #aaa;
26
float: right;
27
font-size: 28px;
28
font-weight: bold;
29
}
30
31
.close:hover,
32
.close:focus {
33
color: black;
34
text-decoration: none;
35
cursor: pointer;
36
}
37
Advertisement
Answer
i used a plugin from this website and tailored it to my needs and it is working perfectly.
https://www.jqueryscript.net/lightbox/jQuery-Multi-Purpose-Popup-Modal-Plugin-popModal.html