Difference between revisions of "JavaScript Prompt"

From Level Access Web Labs
Jump to navigation Jump to search
Line 1: Line 1:
 
<html>
 
<html>
 
<script>
 
<script>
document.getElementById("b1").addEventListener("click",showPrompt)
+
document.addEventListener('DOMContentLoaded', function() {
 +
  document.getElementById("b1").addEventListener("click",showPrompt);
 +
});
 +
 
 
function showPrompt() {
 
function showPrompt() {
 
   var pizza = prompt("Please enter your Fav Pizza", "Veggie, cheese, etc.");
 
   var pizza = prompt("Please enter your Fav Pizza", "Veggie, cheese, etc.");
 
   if (pizza != null) {
 
   if (pizza != null) {
     document.getElementById("demo").innerHTML =
+
     document.getElementById("output").innerHTML =
 
     "Hello you like " + pizza + " ";
 
     "Hello you like " + pizza + " ";
 
   }
 
   }
Line 12: Line 15:
 
<body>
 
<body>
 
<button id="b1">Display prompt</button>
 
<button id="b1">Display prompt</button>
 +
<div id="output"></div>
 
</body>
 
</body>
 
</html>
 
</html>

Revision as of 23:01, 7 February 2019