Denis Stephanov Denis Stephanov - 3 months ago 12
jQuery Question

How to use bootstrap modal in conditions in JavaScript function

how can I implement bootstrap modal window to decide condition in javascript function,
For example, I had created BS modal by BS Docs with "Yes" and "No" buttons, and js function:

function myFunction () {
var modal = $("#myModal").show();

if (modal.userOption == yes) { //do something }
else { //end function }
}


Is possible anything like that? Thanks

Answer

Here is a good Descripiton http://getbootstrap.com/javascript/#modals If you want to listen do the users button Click to something like this: (Plain JQuery)

$('#saveButton').on('click',function(){
    alert("Okay");
});

$('#closeButton').on('click',function(){
    alert("Close");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <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">Modal title</h4>
      </div>
      <div class="modal-body">
        <p>One fine body&hellip;</p>
      </div>
      <div class="modal-footer">
        <button type="button" id="closeButton" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" id="saveButton"class="btn btn-primary">Save changes</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->