Changing Modal Content Based on Trigger Button - HTML CSS Bootstrap

HTML CSS examples for Bootstrap:Modal

Description

Changing Modal Content Based on Trigger Button

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Example of Bootstrap 3 Modal Events</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
  <script type="text/javascript">
$(document).ready(function(){
  $("#myModal").on('show.bs.modal', function(event){
        var button = $(event.relatedTarget);  // Button that triggered the modal
        var titleData = button.data('title'); // Extract value from data-* attributes
        $(this).find('.modal-title').text(titleData + ' Form');
    });<!--  www. j a v a 2s .  c  o m-->
});
</script>
 </head>
 <body>
  <div>
   <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal" data-title="Feedback">Feedback</button>
   <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal" data-title="Report Error">Report Error</button>
   <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal" data-title="Contact Us">Contact Us</button>
   <!-- Modal HTML -->
   <div id="myModal" class="modal fade">
    <div class="modal-dialog">
     <div class="modal-content">
      <div class="modal-header">
       <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
       <h4 class="modal-title">Modal Window</h4>
      </div>
      <div class="modal-body">
       <form role="form">
        <div class="form-group">
         <label for="recipient-name" class="control-label">Email:</label>
         <input type="text" class="form-control" id="recipient-name">
        </div>
        <div class="form-group">
         <label for="message-text" class="control-label">Message:</label> &lt;textarea class="form-control" id="message-text"/>
        </div>
       </form>
      </div>
      <div class="modal-footer">
       <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
       <button type="button" class="btn btn-primary">Send</button>
      </div>
     </div>
    </div>
   </div>
  </div>
 </body>
</html>

Related Tutorials