Hello , I am trying to open a modal through a select
and I have the following codehtml
<select id = "numbers" onchange = "myFunction()">
<option value = "1">1</option>
<option value = "2">2</option>
<option value = "3">Click me !</option>
</select>
<div class="container">
<h2>Basic Modal Example</h2>
<!-- Trigger the modal with a button -->
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×
</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-
dismiss="modal">Close</button>
</div>
</div>
</div>
And the function javascript
that I am using is the following:
function myFunction() {
var option_value = document.getElementById("numbers").value;
if (option_value == "3") {
alert("Hai !");
}
}
The problem is that when choosing option 3 it shows me a alert
, what I am looking for is to show a modal made with boostrap, I tried to put a instead of alert
a $('#myModal').modal('show');
but when choosing nothing came out, how else could I do it?
Thanks.
I add the solution you just have to modify the content of your modal
It works by calling the modal with the show method... check if your modal is in the same document, or if there is an external call, it would also be convenient for you to integrate jquery into your project. This works