mardi 26 septembre 2017

How to get Bootstrap Modal data on laravel 5

I have list of data that i distribute with foreach. And i want to get the detail of each data with bootstrap modal.

This is my code

<div class="container bg-white" style="padding: 20px;">
        @foreach ($hadiah as $h)
        <div class="col-md-6 rewards" >
            <div class="rewards-box">
                <div class="img">
                    <img class="imagePreview" src="http://ift.tt/2fPlNsY}}">
                </div>
                <div class="caption">
                    <h3 class="title"></h3>
                    <p class="point_needed"><span class="fa fa-certificate"></span> </p>
                    <p class="description"></p>
                    <button type="button" class="btn btn-info btn-lg detail-item" id="" data-toggle="modal" data-target="#myModal">Buka</button>
                </div>
            </div>
        </div>
        @endforeach        
    </div>

This is my modal

<div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title"></h4>
      </div>
      <div class="modal-body">
        <div class='row'>
            <center>
                <div class='col-md-12'>
                    <img class="modal-image">
                </div>
            </center>
            <div class='col-md-12'>
                <p align='center' class="modal-poin"><b>Poin dibutuhkan</b></p>
            </div>
            <div class='col-md-12'>
                <p align='justify' class="modal-desc">Deskripsi</p>
            </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>

this is my javascript

<script type="text/javascript">
    $("body").on("click",".detail-item",function(){
        var id = $(this).data('id');
        var nama = $(this).find('title').text();
        var src = $(this).find('.imagePreview').attr('src');
        var poin = $(this).find('point_needed').text();
        var desc = $(this).find('description').text();
        $("#myModal").find(".modal-title").text(nama);
        $("#myModal").find('.modal-image').attr('src', src);
        $("#myModal").find(".modal-poin").text(poin);
        $("#myModal").find(".modal-desc").text(desc);
    });
</script>

The result is nothing shown. And i want to get the detail of each data if i click the button

Thanks for help



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2xwxAGA
via IFTTT

Aucun commentaire:

Enregistrer un commentaire