Nomad Nomad - 4 months ago 11
jQuery Question

How to get value of data-id and place it into a twitter bootstrap modal?

Im trying to get the value of the data-id which contains and id in my database. I need to get the admin_id and place it into a twitter bootstrap modal. How am I going to get that value using java script?

<a data-toggle="modal" data-id="<?=$row['ADMIN_ID'];?>" href="#view_contact" class="btn btn-info btn-xs view-admin">View</a>


here is my modal

<div class="modal fade" id="view_contact" role="dialog">
<div class="modal-dialog">
<div class="modal-content">

<div class="modal-header">
<h4>Admin modal!!</h4>

</div>

<div class="modal-body">
Admin Id:<p id="showid"></p>
</div>

<div class="modal-footer">

<a class="btn btn-default" data-dismiss="modal">Close</a>

</div>


</div>

</div>

</div>


here is my java script

<script type="text/javascript">


$(document).on("click", ".view-admin", function () {
var adminid = $(this).data('id');
$(".modal-body #showid").val( adminid );
$('#view_contact').modal('show');
});

</script>


its not showing in my modal. They are all in the same page. How do I do this? Kinda new at this.

Answer

Problem is, you are trying to assign the value to a p tag. p tag does not have value property. Use text() or html()

$(document).on("click", ".view-admin", function() {
    var adminid = $(this).data('id');
    $(".modal-body #showid").text(adminid);
    $('#view_contact').modal('show');
});
Comments