Function not being called on dialog open

Function not being called on dialog open

I would like the function dialog_close() to be called when the dialog opens.  The web page has two buttons, one to open the dialog and the other to close the dialog. These buttons are just for testing, for now. 

If you click the OPEN button the dialog opens but it never closes.  If you then click the CLOSE button the dialog closes after a 3 second delay.  

If you then click the OPEN button again, the dialog opens again. But, clicking the CLOSE button again does not cause the dialog to close, and neither can you close the dialog using the default close button.

So, I have two problems but for now can we just try and solve the first problem which is the function dialog_close() is not being called when the dialog opens?

Thanks,
TD

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <title>Fire Service Manager - Mobile</title>

  7. <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

  8. <script type="text/javascript" src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  9. <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  10. <script type="text/javascript" src="captcha/src/captcha.min.js"></script>
  11. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  12. <style>
  13. body {
  14. background-color: black;
  15. }
  16. </style>
  17. <script>
  18. function login(){
  19. $("#dialog_login").dialog({
  20. autoOpen: false,
  21. modal: true,
  22. title: "Login Status",
  23.     open: function(){
  24. dialog_close()
  25.     }, 
  26. close: function(){
  27. clrflds()
  28. }
  29. });
  30. $("#dialog_login").html("<br /><div>Login Failed...</div>");
  31. $("#dialog_login").dialog("open");
  32. }
  33. function dialog_close(){
  34. setTimeout(function(){$("#dialog_login").dialog("close");}, 3000);
  35. }
  36. </script>
  37. </head>
  38. <body>
  39. <button onclick="login()">OPEN</button>
  40. <button onclick="dialog_close()">CLOSE</button>
  41. <div id="dialog_login"></div>
  42. </body>
  43. </html>