0

How can I open a modal in another link using this link?

<a href="process.php&data=3" data-toggle="modal"data-target="#modal-view">
 link                         
</a>

And in process.php have this modal and I want to get data from that link.

 <div class="modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">Modal title</h4>
      </div>
      <div class="modal-body">
       <?php $data=$_GET[data]; echo $data; ?>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
George Kagan
  • 5,913
  • 8
  • 46
  • 50
dennis ramli
  • 73
  • 1
  • 2
  • 9

2 Answers2

0

I think you would just need to run the javascript function to load a modal when the page loads.

This post has some good ways to do this: How to open a Bootstrap modal window using jQuery?

In short, something like this would be needed in your javascript in the other page to open the modal when the page loads:

$('#myModal').modal('show');

You may need to give your modal an ID attribute so that it could be easily referenced uniquely.

Community
  • 1
  • 1
cyram
  • 820
  • 8
  • 22
0

Try this,

Add id to a tag

<a id="myLink" href="process.php&data=3" data-toggle="modal"data-target="#modal-view">
 link                         
</a>

Add id to div tag

 <div id="myModal" class="modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">Modal title</h4>
      </div>
      <div class="modal-body">
       <?php $data=$_GET[data]; echo $data; ?>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

And apply click event on your link and load your content remotely,

$('a#myLink').on('click', function(e){
  e.preventDefault();
  $('#myModal').modal('show').find('.modal-body').load($(this).attr('href'));
});
ScanQR
  • 3,740
  • 1
  • 13
  • 30