0

I cant get the data-id attribute value to show in the modal when button is clicked

Here is my button:-

<a class="btn btn-default btn-sm" id="delcompanybtn" data-href="/deletecompany.php?companyid=' + data[0] + '" data-toggle="modal" data-target="#confirm-delete" data-id=' + data[0] + '" ></a>

Here is my Jquery code:-

$('#delcompanybtn').on('show.bs.modal', function (e) {
var companyid = $(e.relatedTarget).attr('data-id');
$('#showcompanyid').html(companyid);
});

Here is my modal body code:-

<div class="modal-body">
Delete Company ID : <span id="showcompanyid"></span> ?
</div>

Silly little things like this just bug me, any help is appreciated!

Rohit Verma
  • 3,657
  • 7
  • 37
  • 75
Chris Yates
  • 243
  • 3
  • 16

1 Answers1

0

solved :

$('#confirm-delete').on('show.bs.modal', function(e) {
  var companyid = $(this).data("id");
  $(this).find('#showcompanyid').html($(e.relatedTarget).attr('data-id'));
    $(this).find('.btn-ok').attr('href', $(e.relatedTarget).data('href'));
});
Chris Yates
  • 243
  • 3
  • 16