add, edit, delete datatables

add, edit, delete datatables

dzuedzue Posts: 2Questions: 1Answers: 0
edited June 2015 in Free community support
<script type="text/javascript">
//New
$("#proses").val('new');
$("#new_kod").prop('readonly', false);
    
//Edit
$(".b_edit").click(function(event){
    var id = $(this).attr('id');
    var kod = $("#kod" + id).val();
    var nama = $("#nama" + id).val().toUpperCase();
                
    $("#new_kod").prop('readonly', true);
    $("#new_kod").val(kod);
    $("#new_nama").val(nama);
    $("#proses").val('edit');
                
    event.preventDefault();
});
//  OnClick b_reset
$("#b_reset").click(function(event){
    $("#new_kod").prop('readonly', false);
    $("#new_kod").val('');
    $("#new_nama").val('');
    $("#proses").val('new');
                
    event.preventDefault();
});

//Delete
$(".b_delete").click(function(event){
    var id = $(this).attr('id');
    var kod = $("#kod" + id).val();
    var nama = $("#nama" + id).val().toUpperCase();
    
    $("#new_kod").val(kod);
    $("#new_nama").val(nama);
    $("#proses").val('delete');
                
    event.preventDefault();
});

$(document).ready(function() {
    $("#simpan").click(function(){
//      var proses = $("#proses").val();
        <!--alert('Test'); -->
        var proses = $("#proses").val();
        var new_kod = $("#new_kod").val();
        var new_nama = $("#new_nama").val();
        
        new_kod = ($.trim(new_kod)).toUpperCase ();
        new_nama = ($.trim(new_nama)).toUpperCase ();
        
        var data = {new_kod:new_kod, new_nama:new_nama};
        
        if(new_kod == "" && new_nama == "")
        {
            $.alert.open('warning', 'Penuhkan maklumat');
            $("#new_kod").focus();
        }
        else if(new_kod == "")
            {
                $.alert.open('warning','Masukkan kod');
                $("#new_kod").focus();
            }
            else if(new_nama == "")
             {
                $.alert.open('warning','Masukkan nama');
                $("#new_nama").focus();
             }
             else 
             {  
                    if(proses == "new")
                    {
                        $.post('../apps/kod.fasa/add.php', data, function(data, status){
                            switch(data)
                            {
                                case    "Berjaya"   :   $.alert.open('confirm', '<h4>Berjaya</h4><hr>Rekod berjaya disimpan..');
                                                        break;
    
                                case    "Gagal"     :   $.alert.open('error', '<h4>Gagal</h4><hr>Rekod gagal disimpan!..');
                                                        break;
    
                                case    "Tiada"     :   $.alert.open('warning', '<h4>Makluman</h4><hr>Rekod telah wujud!..');
                                                        break;

Answers

  • dzuedzue Posts: 2Questions: 1Answers: 0

    i'm using datatables, buy i can't add edit n delete on next page..Page 1 succssess.. but page 2 n so on not working..

This discussion has been closed.