0

I'm using Bootstrap modal popup window,this is the button and url

 <a href="#"  data-toggle="modal" data-target="#applynowModal" data-id="'.$row['id'].'" class="btn   action_button but_apply">Apply Now</a>

 <div class="modal fade" id="applynowModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
   // Modal popup contents
 <div class="modal-body">
 // contents <?php echo $_GET['id'];  // I need to get data-id value here.... ?>
 </div>
</div>

I need to pass a unique id when Apply now button is clicked, and get the value in modal-body, How can I do this?

Renjitha22
  • 213
  • 1
  • 7
  • 22
  • check this example http://stackoverflow.com/questions/10626885/passing-data-to-a-bootstrap-modal http://jsfiddle.net/Au9tc/605/ – Ranjeet Singh May 22 '17 at 09:36

2 Answers2

0

Please note that PHP is a server side script and attaining the "when clicked" event happens on the client side.

Unless you really want the id to be passed only on clicked, you can just passed it as it is.

But then, I'll assume that you really want it to happen only on click. Then you can use a javascript (or bootstrap's jQuery)

$('#applynowModal').on('shown.bs.modal', function () {
  // PUT THE LOGIC HERE OF PASSING THAT ID USING $(this).attr("data-id")
})
ajib
  • 309
  • 2
  • 17
0

Using jquery, it can be easy.

$( '.but_apply' ).click( function() {
    var id = $( this ).attr( 'data-id' ); 
    $( '#applynowModal' ).find( '.modal-body' ).html( id );
}); 
Ukasha
  • 2,238
  • 3
  • 21
  • 30