Advertisement
Guest User

modal

a guest
Oct 14th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4.     <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  5.     <title>Jota</title>
  6.     <link href="style.css" rel="stylesheet" type="text/css" media="screen" />
  7.     <script>
  8.         //configuration
  9.         var codes = new Map();
  10.         codes.set("1234", "output");
  11.         codes.set("1234", "output");
  12.        
  13.         var errorMsg = "Error bericht";
  14.     </script>
  15. </head>
  16. <body>
  17.    
  18.     <!-- Trigger/Open The Modal -->
  19.     <input id="JotaCode">
  20.     <button id="myBtn">Open Modal</button>
  21.    
  22.     <!-- The Modal -->
  23.     <div id="myModal" class="modal">
  24.  
  25.       <!-- Modal content -->
  26.       <div class="modal-content">
  27.         <span class="close">&times;</span>
  28.         <p id="modal-text">Some text in the Modal..</p>
  29.       </div>
  30.  
  31.     </div>
  32.    
  33.     <script>
  34.         // Get the modal
  35.         var modal = document.getElementById("myModal");
  36.  
  37.         // Get the button that opens the modal
  38.         var btn = document.getElementById("myBtn");
  39.  
  40.         // Get the <span> element that closes the modal
  41.         var span = document.getElementsByClassName("close")[0];
  42.  
  43.         // Get the <p> text
  44.         var modalText = document.getElementById("modal-text");
  45.        
  46.         // When the user clicks on the button, open the modal
  47.         btn.onclick = function() {
  48.             modal.style.display = "block";
  49.            
  50.             //Get the value from the map with the key from the input field
  51.             var codeResult = codes.get(document.getElementById("JotaCode").value);
  52.            
  53.             // If a value is returned, show the text. or else show an error message
  54.             if(codeResult != null) {
  55.                 modalText.innerHTML = codeResult;
  56.             } else {
  57.                 modalText.innerHTML = errorMsg;
  58.             }
  59.         }
  60.  
  61.         // When the user clicks on <span> (x), close the modal
  62.         span.onclick = function() {
  63.           modal.style.display = "none";
  64.         }
  65.  
  66.         // When the user clicks anywhere outside of the modal, close it
  67.         window.onclick = function(event) {
  68.           if (event.target == modal) {
  69.             modal.style.display = "none";
  70.           }
  71.         }
  72.     </script>
  73. </body>
  74. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement