How do I get the data id value and put it in the twitter bootstrap modal?

I am trying to get a data id value which contains both id in my database. I need to get the admin_id and put it in the twitter bootstrap modal. How can I get this value using a 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>

      

it doesn't show up in my modal view. They are all on the same page. How should I do it? Its new in this.

+3


source to share


2 answers


The problem is you are trying to assign a value to a tag p

. The tag p

has no value property. Use text()

orhtml()



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

      

+3


source


You can just replace

$(".modal-body #showid").val( adminid );

      

from



$("#showid").text( adminid );

      

You don't need to reference the class name .modal-body

for id #showid

as there should only be one id name per page per W3C Validation . And id references are the fastest way to access any html elements.

0


source







All Articles