Abdul Muqeet
Abdul Muqeet

Reputation: 201

Passing data to bootstrap modal

After searching alot I find many solution to pass data to my model but nothing work , this is my code can any point out where am I making a mistake? when i clicked my model nothing shows up. and Can I do it through PHP ? whitout using javascript

<td>
    <a data-id="<?echo $comments;?>" class="open-AddBookDialog" href="#myModal"><?echo substr($comments,0,10)?></a>
</td>

<div class="modal fade" id="#myModal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Modal Header</h4>
            </div>
            <div class="modal-body">
                <p>
                    Some text
                </p>
                <input type="text" name="bookId" id="bookId" value="" />
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

Jquery

 $(document).on("click", ".open-AddBookDialog", function (e) {

    e.preventDefault();

    var _self = $(this);

    var myBookId = _self.data('id');
    $("#bookId").val(myBookId);

    $(_self.attr('href')).modal('show');
});

Upvotes: 1

Views: 8593

Answers (1)

Alex Coloma
Alex Coloma

Reputation: 636

Change this:

<div class="modal fade" id="#myModal" role="dialog">

to this:

<div class="modal fade" id="myModal" role="dialog">

...without '#'

Upvotes: 3

Related Questions