Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does not open bootstrap modal dialog in the second time?

I have used a bootstrap modal dialog that is opened by clicking button. When I click on button at the first time,modal is opened; by the second clicking, modal dialog does not show and this error is shown in firebug consol:

TypeError: $(...).modal is not a function
$(".bs-modal-dialog").modal();

how can i solve that? thanks...

these are my code:

<div class="modal fade bs-modal-dialog" id="modalDialog" tabindex="-1" role="dialog" 
 aria-labelledby ="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
    <div class="modal-content">
        <div class="modal-header">

                 <button class="close" aria-hidden="true" data-dismiss="modal" type="button">×</button>
                  <h4 id="mySmallModalLabel" class="modal-title"></h4>
        </div>
        <div class="modal-body">
        </div>
    </div>
</div>

<script>

function EditCompany(CoId) { 


    var link="@Url.Action("EditCompany", "Companies", new { area = "AdminsArea", CoId = "-1"})";

        link=link.replace("-1",CoId);
        $(".bs-modal-dialog").modal('show');
        $(".modal-body").load(link);
        $(".modal-content > .modal-header> #mySmallModalLabel").text("Edit Company");

} 

                    <input type="button" name="EditCompany" value="Edit"  onclick="EditCompany(@co.CompanyID)" class="btn btn-success"/>
like image 620
mortazavi Avatar asked May 30 '14 11:05

mortazavi


People also ask

How do I stop a Bootstrap modal from closing?

If you want to prevent boostrap modal from closing by those actions, you need to change the value of backdrop and keyboard configuration. The default value of backdrop and keyboard is set to true . You can change the configuration in HTML or Javascript directly.

How do you prevent Bootstrap 4 modal from closing when clicking outside?

On Options chapter, in the page you linked, you can see the backdrop option. Passing this option with value 'static' will prevent closing the modal.

How do I know if a Bootstrap modal is open?

How check modal is open or not in jQuery? You can simply use the modal('show') method to show or open the modal window in Bootstrap using jQuery. Other related Bootstrap's modal methods are modal('hide') and modal('toggle') .

How do I toggle Bootstrap modal?

To trigger the modal window, you need to use a button or a link. Then include the two data-* attributes: data-toggle="modal" opens the modal window. data-target="#myModal" points to the id of the modal.


1 Answers

You don't need any JavaScript to do that, Bootstrap already comes with html attribute for that.

All you have to do this include data-toggle="modal" data-target="#myModal" and it should trigger your modal.

bootply here

like image 151
nolawi Avatar answered Oct 01 '22 09:10

nolawi