x
 
1
<!DOCTYPE html>
2
<title>My Example</title>
3
4
<script>
5
// Wait for DOM to load
6
document.addEventListener("DOMContentLoaded", function(event) {
7
8
  // Put the button into a variable
9
  var e = document.getElementById("go");
10
  
11
  // Wait for user to click the button
12
  e.addEventListener( "click", function() {
13
14
    // Do the prompt and save user input to a variable
15
    var name = prompt("What is your name?","Homer");
16
    
17
    // Write out the user's input
18
    document.getElementById( "msg" ).innerText = name;
19
20
  }, false);
21
  
22
});
23
</script>
24
25
<!-- Replace '{action page}' with your own action page to support non-JavaScript users -->
26
<input id="go" type="button" value="Click me">
27
<p id="msg"></p>