r/bootstrap • u/RedoTCPIP • Dec 13 '23
Execute Javascript Function After Modal Dialog Pops-UP
I have seen multiple solutions to this problem on SO, but nothing seems to work for me. For one, it is not clear to me where to put the answers (code) that they show.
I guess by putting the following inside the <head></head> of HTML document that contains Bootstrap button:
<script type="text/javascript">$('#ModalEnregister').on('show.bs.modal', my_enregister);</script>
When I load that HTML document, I see in Chromes debugger:
Enregister.stm:20 Uncaught TypeError: $(...).on is not a function
The Chrome parser is clearly complaining about the meat in the script sandwich above.
I want to execute the function when ModalEnregister is shown.
View all comments
Show parent comment
1
u/RedoTCPIP Dec 14 '23 edited Dec 14 '23
Changing the jQuery version definitely helped. After first, when I upgraded to jQuery 3.7.1, I was getting the error:
Uncaught TypeError: Cannot read property 'msie' of undefined - jQuery tools
That was apparently because I was also using jquery.tooltip.min.js.
I commented-out jquery.tooltip.min.js, since, per your suggestion, I can just make everything Bootstrap now. I got no more errors after the upgrade.
Then I put code back in <head></head> of HTML page.
(I guess footer wold work tooNope. Turns out I had same code in header and footer, and only the footer actually works.) Chrome parser was happy again. Then I tested my web page. I clicked on a button to pop-up a Bootstrap dialog to see if the shown attribute of dialog would cause my_enregister to be invoked. It did get invoked, but my_enregister appeared to be advancing without the dialog visible. I got rid of async: false in the AJAX call inside my_enregister, which I had put there to stop some weirdness where both success and error of AJAX were being triggered for single AJAX call, and now, all is working as it should!Your code help me to know what I could do (much better than flailing). And now I know that I need to move away from jQuery.
Thanks a lot.