1

How to generate a modalpopup in bootstrap when a value in a dropdown is changed?

I have my javascript like this ..I am raising an event to show the modalPopup

$("#City").change(function () {
   if ( $("option:selected", $("#City")).text() == "Others") {
       alert("hi");
       showModalPopup();
   }
});


function showModalPopup() {
   $("#myModal").modal("show");
}

I am getting the alert but I am unable to see the modal popup.

And this is the html code for that popup from bootstrap example

<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
    <p>One fine body…</p>
</div>
<div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-primary">Save changes</button>
</div>

I am new to bootstrap .Please help me out.

madth3
  • 7,275
  • 12
  • 50
  • 74
Bharat Bhushan
  • 1,315
  • 3
  • 18
  • 24

1 Answers1

1

First add Variable for your dropdown change event

$("#City").live("change", function () {
   var changeCity = "";
   changeCity =  $("#City option:selected").val();
           if ( changeCity  == "Others") {
               alert("hi");
               showModalPopup();
           }
        });


        function showModalPopup() {
           $("#myModal").modal("show");
        }

Hope this works :)

Enrique Gil
  • 754
  • 4
  • 19
  • 50