14

I have a button on my page that when it is pushed it triggers some javascript functions to occur, and one of those javascript functions to open a bootstrap modal, but I can't seem to get it to work. Here is my code... please help.

 //elsewhere on the form is the button that triggers the javascript
  <a href="#" class="btn btn-danger" id="cancelPObtn" data-dismiss="modal">Yes, cancel it</a>

 <!-- CANCEL A PO MODAL -->
 <div class="modal hide fade" id="error-dialog" style="display: none;">
   <div class="modal-header">
        <a class="close" data-dismiss="modal">x</a>
        <h3>Cancel Purchase Order?</h3>
   </div>
   <div class="modal-body">
   </div>
   <div class="modal-footer">
       <a href="#" class="btn btn-danger btn-modal btn-cancel"  data-dismiss="modal">Yes, cancel it</a>
       <a href="#" class="btn" data-dismiss="modal">Nevermind</a>
   </div>
 </div>




      $('.btn-danger').click(function(event) {
          if(some random conditional statement){
             //some stuff happens here
          }
          else{ 
                //Show form validation error modal-- I know this part is triggered but the modal will not show
                $("#error-dialog").modal("show");
          }
      });

3 Answers 3

7

$("#error-dialog").modal("show");

This is the correct way, your code simply has an error. Go in to Chrome Console and run this command, it'll work.

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

1 Comment

Simple one liner, easy to use and functional. Thank you Andy!
4

you're missing if () { part of the conditional statement

2 Comments

I accidently removed the if() when I entered the question. The real solution was I needed to remove the style tag style="display: none;" from the modal.
@JSilva If this was not really the problem with your question then please don't accept this answer. This just confuses people when they read this question.
3

It's a bit hard to see what you want to do with this partial code, but here is a working code based on yours:

http://jsbin.com/oqomiv/1/edit

Comments

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.