Tolong pilih kategori sesuai, jenis posting (diskusi atau bukan) dan sertakan tag/topik yang sesuai seperti komputer, java, php, mysql, dll. Promosi atau posting tidak pada tempatnya akan kami hapus!
- Bagi Anda yang ingin mendaftar, baca link berikut:
http://diskusiweb.com/discussion/50491/how-to-registrasi-diskusiweb-com-baca-ini-terlebih-dahulu
- Cara menyisipkan kode program supaya tampil rapi dan terformat dengan baik di diskusiweb.com: http://www.diskusiweb.com/discussion/50415/cara-menyisipkan-kode-program-di-diskusiweb-com
- Cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

javascript konfirmasi delete di dalam php

sore master,
saya ada view row, di setiap row ada link buat delete, nah yg jadi masalah sy pas klik delete ada event buat alert data mau di hapus tp ga jalan

$rows .='<a title="Delete" onClick="return confirm("Delete This account?")"  class="a-danger" href="'.base_url().'setup/agama/delete/'.$r->id.'">

kalau saya taro di luar php jalan codenya.
 <a href="<?php echo base_url();?>cuti/data_cuti_karyawan/delete" onClick="return confirm('Delete This account?')" class="btn btn-danger"><i class="fa fa-arrow-left"></i> Delete</a>

Mohon bantuannya 
^:)^

Comments

  • edited August 2016
    coba ikutin dr ini :
    $action['href'] = link delete 

    <td>
    <?php foreach ($mn as $action)
      { ?>
    [ <a href="javascript:confirmDelete('<?php echo $action['href'];?>')">DELETE</a> ]
    <?php } ?>
    </td>

    <script type="text/javascript">
    function confirmDelete(delUrl) {
    if (confirm("Are You Sure Want Delete This Menu ??")) {
    document.location = delUrl;
    }
    }
    </script>

    atau kalo pusing COPAS INI KE NEW PHP (LINK-nya saya ngga set):

    [ <a href="javascript:confirmDelete('<?php echo LINK DELETE;?>')">DELETE</a> ]

    <script type="text/javascript">
    function confirmDelete(delUrl) {
    if (confirm("Are You Sure Want Delete This Menu ??")) {
    document.location = delUrl;
    }
    }
    </script>


    Hasil [DELETE] => popup => delete/cancel
  • ia mas script dari mas bisa jalan,
    masalahnya sy coba untuk code sy msh blm jalan. Bingung mau taro function javascriptnya dimana ?
    Karena saya di sini pake CI. Nah tulisan deletenya juga di load pake json ke controller.

    Sy taro javascripttnya di view dia ga ada respon.
    Sy taro di controller bingung karena kontroller itu kan php. Di dalam php di masukin javascript bisa ga mas ?
    <php
    ....
    ....
    <script type="text/javascript">
    function confirmDelete(delUrl) {
    if (confirm("Are You Sure Want Delete This Menu ??")) {
    document.location = delUrl;
    }
    }
    </script>
    ?>

  • edited September 2016
    sy juga pake CI sih cuman mungkin beda sedikit konsep-nya,
    setau saya function js itu di view dhe, controller cuman proses ama isi2 variable
    kl bisa share ama js-nya buat di test

  • ini view nya mas

    <table id="data-table">
    <thead>
    <tr>
    <th>No.</th>
    <th>Nama Agama</th>
    <th>Action</th>
    </tr>
    </thead>
    <tbody>
    <!--Appended by Ajax-->
    </tbody>
    </table>
    <script>
    function get_data(url,q){
     
    if(!url)
    url = base_url+'setup/agama/get_data';
     
    $.ajax({
     
    url:url,type:'post',dataType:'json',
    data:{q:q},
    success:function(result){
     
    $("#data-table tbody").html(result.rows);
    $("ul.pagination").html(result.paging);
    $(".page-info").html(result.page_info);
    }
     
    });
    }
    function do_search(){
     
     
    get_data('',$("#search").val());
     
    }
    $(function(){
     
    get_data();//initialize
     
    $(document).on('click',"ul.pagination>li>a",function(){
     
    var href = $(this).attr('href');
    get_data(href);
     
    return false;
    });
     
    $("#search").keypress(function(e){
     
    var key= e.keyCode ? e.keyCode : e.which ;
    if(key==13){ //enter
     
    do_search();
    }
     
    });
     
    $("#btn-search").click(function(){
     
    do_search();
     
    return false;
    });
     
    });
     
    </script>



    ini controllernya

    <?php
    public function get_data(){
     
    $limit = $this->config->item('limit');
    $offset= $this->uri->segment(4,0);
    $q = isset($_POST['q']) ? $_POST['q'] : '';
    $data = $this->agama_model->get_data($offset,$limit,$q);
    $rows = $paging = '';
    $total = $data['total'];
     
    if($data['data']){
     
    $i= $offset+1;
    $j= 1;
    foreach($data['data'] as $r){
     
    $rows .='<tr>';
     
    $rows .='<td width="5%">'.$i.'</td>';
    $rows .='<td width="40%">'.$r->nama_agama.'</td>';
    $rows .='<td width="20%" align="center">';
     
    $rows .='<a title="Edit" class="a-warning" href="'.base_url().'setup/agama/edit/'.$r->id.'">
    <i class="fa fa-pencil"></i> Edit
    </a> ';
    $rows .='<a title="Delete" class="a-danger" href="javascript:confirmDelete('.base_url().'setup/agama/delete/'.$r->id.')">
    <i class="fa fa-times"></i> Delete
    </a> ';
     
    $rows .='</td>';
     
    $rows .='</tr>';
     
    ++$i;
    ++$j;
    }
     
    $paging .= '<li><span class="page-info">Displaying '.($j-1).' Of '.$total.' items</span></i></li>';
    $paging .= $this->_paging($total,$limit);
     
     
    }else{
     
    $rows .='<tr>';
    $rows .='<td colspan="6">No Data</td>';
    $rows .='</tr>';
     
    }
     
    echo json_encode(array('rows'=>$rows,'total'=>$total,'paging'=>$paging));
    }
     
    private function _paging($total,$limit){
     
    $config = array(
     
    'base_url' => base_url().'setup/agama/get_data/',
    'total_rows'=> $total,
    'per_page' => $limit,
    'uri_segment'=> 4
     
    );
    $this->pagination->initialize($config);
     
    return $this->pagination->create_links();
    }
    ?>
  • mas @blackarch bisa bantu ga mas ?
  • harus-nya sih bisa dhe di simpan k json lalu di call di view, 
    dimn view-nya di pasang javascript-nya.
    coba kamu ganti script-nya tambahin onload:
    <script type="text/javascript">
    $(document).ready(function(){
    function confirmDelete(delUrl) {
    if (confirm("Are You Sure Want Delete This Menu ??")) {
    document.location = delUrl;
    }
    }
    });
    </script>
    kl msh ngga bs coba di tulis code delete di view-nya langsung aja, cuman buat test aja, lalu di run jln ngga?
Sign In or Register to comment.