mortazavi
mortazavi

Reputation: 401

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"/>

Upvotes: 8

Views: 10334

Answers (1)

nolawi
nolawi

Reputation: 4649

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

Upvotes: 4

Related Questions