0

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

1
  • 1
    no, that's not possible, you need a 2nd function, nested or sibling, to continue processing after the user makes a choice; a callback Commented Aug 17, 2016 at 20:06

2 Answers 2

3

Here is a good Descripiton http://getbootstrap.com/javascript/#modals If you want to listen to the users button Click, do 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 -->

Sign up to request clarification or add additional context in comments.

Comments

2

Use http://bootboxjs.com/

bootbox.confirm("Are you sure?", function(result) {
  if(result){
    // do something
  }
}); 

1 Comment

thanks, but i've used other solution without external library

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.