I have created series of button in table field. Now, since the id for all the button is same I want the modal is work for all the button but it is working only for the first button.
<script>
var modal = document.getElementById("myModal");
var btn = document.getElementById("mbutton");
var span = document.getElementsByClassName("close")[0];
btn.onclick = function() {
modal.style.display = "block";
}
span.onclick = function() {
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
while ($row = $result->fetch_assoc()) {
$sl++;
echo "<tr><td>". $sl. "</td><td>". $row['name']. "</td><td>". $row['Total_Trip']."</td><td>".$row['Total_Amount']."</td><td>".$row['Total_Pay']."</td><td>".$row['Total_Due']."</td><td>"."<button id='mbutton'>Pay</button><button id='mbutton'>Report</button>"."</td></tr>";
}
<div id="myModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<span class="close">×</span>
<h2>Pay to</h2>
</div>
<div class="modal-body">
<form>
<label>Payment Amount</label><br>
<input type="text" name="paymodal" placeholder="Amount"><br>
<input type="submit" name="smitModal">
</form>
</div>
</div>