Skip to content
Advertisement

How can I call a function when a Bootstrap modal is open?

I use Boostrap 3.7 and Blade (Laravel 5.5).

I’m trying to display console.log('works') when my boostrap modal opens but it didn’t work.

HTML :

JavaScript

JS :

JavaScript

I followed this doc : https://getbootstrap.com/docs/3.3/javascript/#modals

And I already read that : Calling a function on bootstrap modal open

Thank’s for help !

EDIT 1:

I solved the problem with this code :

JavaScript

But how to differenciate modals (because they are into foreach loop)?

Something like :

JavaScript

Advertisement

Answer

I think your event listeners are created before HTML printing. So try this code.

JavaScript

$(document).on(‘show.bs.modal’, ‘#reservationModal’, function (e) {});

the bold characters will help to identify your modal

ANSWER FOR YOUR UPDATED PART

run the loop and create your modal as follows

JavaScript

Give reservationModal as class

and id as an incremented value appended to it

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement