dimanche 1 janvier 2017

onclick event only work on first child (laravel foreach)

i make button action on every data from table row. every row produce using foreach laravel blade template. the event will trigger a javascript action to delete data. but on my case the button only work on first row data. here my Javascript and html code :

function hapusFaskes(kode){
        var kodeStr = kode.toString();
        var mes = confirm('Yakin Faskesnya mau di Hapus?');
        alert(kode);
        if (mes == true){
            $.ajax({
                headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                url:''+'/'+kode,
                type:'get',
                success: function (r){
                    console.log(r);
                    alert(r);
                    location.reload();
                }
        });
        }
    }
<tbody id="hasil-tabel">
  @foreach ($faskes as $val)
  <tr>
     <td></td>
     <td></td>
     <td></td>
     <td></td>
     <td></td>
     <td></td>
     <td>
         <a href="" class="btn btn-default" >Edit</a>
         <a href="#" type="button" onclick="hapusFaskes()" class="btn btn-default" data-toggle="modal" data-target="#modal-faskes_delete">Hapus</a>
     </td>
  </tr>
  @endforeach
</tbody>

i don't know if there are something wrong on my code, if you know something wrong, please inform me and that will be a big help for me if you know smothing wrong on my code. thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire