I'm just new to PHP and JavaScript that's why i used the samplecode in w3schools and tried to improve it. And I have this one problem with modals. my modal is not opening when clicked. Only my edit button on my first row is working but the rest is not. here's my code for populating the data from my database:
<table>
<tbody>
<?php
require 'connection.php';
$query = "SELECT first,middle,last,rfidnum,section FROM `members`";
$result1 = mysqli_query($con, $query);?>
<?php while($row1 = mysqli_fetch_array($result1)):;?>
<tr class="mems">
<td>
<?php echo $row1[0]; ?>
</td>
<td>
<?php echo $row1[1]; ?>
</td>
<td>
<?php echo $row1[2]; ?>
</td>
<td>
<?php echo $row1[3]; ?>
</td>
<td>
<?php echo $row1[4]; ?>
</td>
<td>
<button id='edit'>Edit</button>
</td>
</tr>
<?php endwhile;?>
</tbody>
</table>
<!-m2content->
<div id="myModal2" class="modal2">
<div class="modal2-content bounceInDown animated">
<span class="close2">×</span>
<table>
<thead><th>Add Member</th></thead>
<tbody>
<tr>
<td></td>
<td>
<form method="post">
<table>
<tr><td>First Name</td>
<td><input class="textboxx" type="text" name="first" onkeypress=" return forinput()" ></td></tr>
<tr><td>Middle Name</td>
<td><input class="textboxx" type="text" name="middle" onkeypress=" return forinput()" ></td></tr>
<tr><td>Last Name </td>
<td><input class="textboxx" type="text" name="last" onkeypress=" return forinput()" ></td></tr>
<tr><td>ID Number: </td>
<td><input class="textboxx" type="text" name="idnumber" onkeypress=" return forinput()" ></td></tr>
<tr><td>Section: <br>
<td><input class="textboxx" type="text" name="section" onkeypress=" return forinput()"> </td></tr>
<tr><td><input type="submit"></td></tr>
</table>
</form>
</td>
</tr>
</tbody>
</table>
</div>
while this is my Java Script:
// Get the modal
var modal2 = document.getElementById('myModal2');
// Get the button that opens the modal
var btn2 = document.getElementById("edit");
// Get the <span> element that closes the modal
var span2 = document.getElementsByClassName("close2")[0];
// When the user clicks the button, open the modal
btn2.onclick = function() {
modal2.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span2.onclick = function() {
modal2.style.display = "none";
}
window.onclick = function(event) {
if (event.target === modal2) {
modal2.style.display = "none";
}
}
Thanks for responses. i'm not using Bootstrap because of my professor. they told us not to use predefined codes. that's why until now i'm stucked with this problem.