Advertisement
Guest User

Untitled

a guest
Jul 31st, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. <a data-toggle="modal" data-id="@book.Id" title="Add this item" class="open-AddBookDialog"></a>
  2.  
  3. <div class="modal hide" id="addBookDialog">
  4. <div class="modal-body">
  5. <input type="hidden" name="bookId" id="bookId" value=""/>
  6. </div>
  7. </div>
  8.  
  9. $(document).ready(function () {
  10. $(".open-AddBookDialog").click(function () {
  11. $('#bookId').val($(this).data('id'));
  12. $('#addBookDialog').modal('show');
  13. });
  14. });
  15.  
  16. <p>Link 1</p>
  17. <a data-toggle="modal" data-id="ISBN564541" title="Add this item" class="open-AddBookDialog btn btn-primary" href="#addBookDialog">test</a>
  18.  
  19. <p>&nbsp;</p>
  20.  
  21.  
  22. <p>Link 2</p>
  23. <a data-toggle="modal" data-id="ISBN-001122" title="Add this item" class="open-AddBookDialog btn btn-primary" href="#addBookDialog">test</a>
  24.  
  25. <div class="modal hide" id="addBookDialog">
  26. <div class="modal-header">
  27. <button class="close" data-dismiss="modal">×</button>
  28. <h3>Modal header</h3>
  29. </div>
  30. <div class="modal-body">
  31. <p>some content</p>
  32. <input type="text" name="bookId" id="bookId" value=""/>
  33. </div>
  34. </div>
  35.  
  36. $(document).on("click", ".open-AddBookDialog", function () {
  37. var myBookId = $(this).data('id');
  38. $(".modal-body #bookId").val( myBookId );
  39. // As pointed out in comments,
  40. // it is superfluous to have to manually call the modal.
  41. // $('#addBookDialog').modal('show');
  42. });
  43.  
  44. <a href="#my_modal" data-toggle="modal" data-book-id="my_id_value">Open Modal</a>
  45.  
  46. //triggered when modal is about to be shown
  47. $('#my_modal').on('show.bs.modal', function(e) {
  48.  
  49. //get data-id attribute of the clicked element
  50. var bookId = $(e.relatedTarget).data('book-id');
  51.  
  52. //populate the textbox
  53. $(e.currentTarget).find('input[name="bookId"]').val(bookId);
  54. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement