2

I want to set value for kode_lahan same with kode, I send value kode when I click delete button. But, when I run my code, kode_lahan value is undefined

function tampilLahan(){
        $.ajax({
            type  : 'ajax',
            url   : base_url+"investasi/tampilDataPermintaan",
            async : true,
            dataType : 'JSON',
            success : function(data){
                var html = '';
                var i;
                for(i=0; i<data.length; i++){
                  var kode = data[i].kode;
                    html += '<tr>'+
                            '<td>'+kode+'</td>'+
                            '<td>'+
                            '<a href="javascript:void(0);"class="btn btn-danger item_delete" kode="'+kode+'">Delete</a>'+
                            '</td>'+
                            '</tr>';
                }
                $('#data').html(html);
            }
        });
    }

  $('#data').on('click','.item_delete',function(){
  var kode_lahan = $(this).data("kode");
  console.log(kode_lahan);

    });

I expect the output of kode value

1 Answer 1

2

You're setting the kode attribute in your AJAX, but looking for the data-kode attribute - it's better to go with data-kode because kode isn't a valid attribute name, so rename it when it's being set.

'<a href="javascript:void(0);"class="btn btn-danger item_delete" data-kode="'+kode+'">Delete</a>'+
Sign up to request clarification or add additional context in comments.

1 Comment

No problem @taufik, always glad to help. If my answer fixed your problem, please mark it as accepted by clicking the grey tick mark to the left of my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.