0

body html code:
note: that id is to differentiate the button click

 foreach($threads as $t) { ?>
 <button id="myBtn<?php echo $ids;?>" Open Modal</button>
 <? } ?>                                

This is the modal code how can apply fetch data in here modal?:

<!-- The Modal -->

 <div id="myModal1" class="modal">
                       <!-- Modal content -->
    <div class="modal-content">
                    <div class="modal-header">
                            <span class="close">&times;</span>
                            <h2>Modal Header</h2>
                     </div>
                <div class="modal-body">
                  <p>Some text in the Modal Body</p>
                  <p></p>
                </div>
            <div class="modal-footer">
                <h3>Modal Footer</h3>
           </div>
     </div>
</div>

This is the Javascript:

     <script type="text/javascript">

     // Get the modal
    var modal = document.getElementById('myModal1');
   // Get the button that opens the modal
    var btn = document.getElementById("myBtn1");
   // Get the <span> element that closes the modal
  var span = document.getElementsByClassName("close")[0];
  // When the user clicks the button, open the modal 
  btn.onclick = function() {
    modal.style.display = "block";
   }

   // When the user clicks on <span> (x), close the modal
  span.onclick = function() {
    modal.style.display = "none";
  }

   // When the user clicks anywhere outside of the modal, close it
  window.onclick = function(event) {
     if (event.target == modal1) {
      modal.style.display = "none";
     }
 }
    </script>

How can I manage modal in different value, if I'm fetching data from the database?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Mavs Mavs
  • 409
  • 1
  • 4
  • 10
  • Rather than showing the modal dialog as part of `onclick` you want to call a function which posts an AJAX call back to your server. Then in the success event of that AJAX call you call a function which renders the result. That render result function determines the right modal dialog box to show and then shows it with the retrieved data. – David Thomas Jan 16 '17 at 07:17
  • Possible duplicate of [jQuery: Load Modal Dialog Contents via Ajax](http://stackoverflow.com/questions/3837166/jquery-load-modal-dialog-contents-via-ajax) – d.coder Jan 16 '17 at 07:31
  • i try the code but when clicking in other button , not works well.. not open pop windows modal. – Mavs Mavs Jan 16 '17 at 09:17

0 Answers0