1

I want to pass data in Bootstrap. I tried using the getbootstrap.com API, but it's not working. I also checked stackoverflow answers but it's still not working. I am pasting the whole page of my sample index - please check it. This is the example that isn't working for me:

I am using the latest version of Bootstrap, which is v3.2.0

Passing data to a bootstrap modal

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>Sample MOdel</title>

    <!-- Bootstrap core CSS -->
    <link href="./dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="./dist/css/cover.css" rel="stylesheet">
    <link href="./dist/css/signin.css" rel="stylesheet">
    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="./assets/js/ie-emulation-modes-warning.js"></script>

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="./assets/js/ie10-viewport-bug-workaround.js"></script>

    <script>
       $(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');
       });
    </script>

  </head>

  <body>

    <div class="site-wrapper">

      <div class="site-wrapper-inner">

        <div class="cover-container">



    <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>&nbsp;</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>



<!-- Modal -->
<div class="modal fade" id="addBookDialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel" style="color: black;">Sample Model</h4>
      </div>
      <div class="modal-body">
          <div class="err" id="add_err"></div>


          <div class="modal-body">
        <p>some content</p>
        <input type="text" name="bookId" id="bookId" value=""/>
    </div>

      </div>

    </div>
  </div>
</div>        

        </div>

      </div>

    </div>


    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="./dist/js/bootstrap.min.js"></script>
    <script src="./assets/js/docs.min.js"></script>
  </body>
</html>
Community
  • 1
  • 1
MKDEV
  • 23
  • 3
  • 1
    Seems like you are not wrapping it on the .ready(). Look at the example again (at the actual question). – Hanlet Escaño Jul 15 '14 at 21:25
  • @Hanlet Escaño bro i want to pass basically php dyanmic data i do that please do help me for the code its very good for me i am totally stuck and shaking middle finger i am basically php developer i am very sorry i can't get soo much know about the jquery please its my request that do correct and working code. thanks in advance – MKDEV Jul 15 '14 at 22:06

1 Answers1

0

It is difficult to explain in a comment, so go ahead and try this:

$(document).ready(function () {
    $(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');
    });
});

The $(document).ready(function(){}); part gets executed when the document (DOM) is loaded. That might be the reason why your code is not working.

Hanlet Escaño
  • 17,114
  • 8
  • 52
  • 75