Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <a data-toggle="modal" data-id="@book.Id" title="Add this item" class="open-AddBookDialog"></a>
- <div class="modal hide" id="addBookDialog">
- <div class="modal-body">
- <input type="hidden" name="bookId" id="bookId" value=""/>
- </div>
- </div>
- $(document).ready(function () {
- $(".open-AddBookDialog").click(function () {
- $('#bookId').val($(this).data('id'));
- $('#addBookDialog').modal('show');
- });
- });
- <p>Link 1</p>
- <a data-toggle="modal" data-id="ISBN564541" title="Add this item" class="open-AddBookDialog btn btn-primary" href="#addBookDialog">test</a>
- <p> </p>
- <p>Link 2</p>
- <a data-toggle="modal" data-id="ISBN-001122" title="Add this item" class="open-AddBookDialog btn btn-primary" href="#addBookDialog">test</a>
- <div class="modal hide" id="addBookDialog">
- <div class="modal-header">
- <button class="close" data-dismiss="modal">×</button>
- <h3>Modal header</h3>
- </div>
- <div class="modal-body">
- <p>some content</p>
- <input type="text" name="bookId" id="bookId" value=""/>
- </div>
- </div>
- $(document).on("click", ".open-AddBookDialog", function () {
- var myBookId = $(this).data('id');
- $(".modal-body #bookId").val( myBookId );
- // As pointed out in comments,
- // it is superfluous to have to manually call the modal.
- // $('#addBookDialog').modal('show');
- });
- <a href="#my_modal" data-toggle="modal" data-book-id="my_id_value">Open Modal</a>
- //triggered when modal is about to be shown
- $('#my_modal').on('show.bs.modal', function(e) {
- //get data-id attribute of the clicked element
- var bookId = $(e.relatedTarget).data('book-id');
- //populate the textbox
- $(e.currentTarget).find('input[name="bookId"]').val(bookId);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement