How to bind dynamic data in one boot modal

I have one modal in my form

<div class="modal fade" id="myModal" 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" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Image Tag Description</h4>
      </div>
      <div class="modal-body">
          <p id="desc">
        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
      </p>
          <h2 id="cost">Cost : 20$</h2>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">Edit</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

and I have some buttons that are toggel modal. After pressing the button

<button class="btn btn-primary tag_cnt" data-trigger="hover" 
        data-target="#myModal" data-toggle="modal" type="button" 
        style="top:144px; left:510px" value="1"></button>

I have some buttons in my form. now I have to call the same modal every time I press the button, and I want to show dynamically the data in modal mode. What is the solution?

+4
source share
1 answer

You can pass the daily variable to a function, and then to a function that you can use the variable:

<button class="btn btn-primary tag_cnt" style="top:144px; left:510px" onclick="showModal('data')" type="button" value="1"></button>

And in the script, you can access this data as follows:

function showModal(data)
{
   //you can do anything with data, or pass more data to this function. i set this data to modal header for example
   $("#myModal .modal-title").html(data)
   $("#myModal").modal();
}
+8
source

All Articles