×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Peter Hempel
Added: Sep 17, 2017 2:31 PM
Views: 6
Tags: no tags
simple action/function added to a button
  1. <button onclick="myFunction()">Try it</button>
  2.  
  3. <p id="demo"></p>
  4.  
  5. <script>
  6. function myFunction() {
  7.     var txt;
  8.     var person = prompt("Please enter your name:", "Harry Potter");
  9.     if (person == null || person == "") {
  10.         txt = "User cancelled the prompt.";
  11.     } else {
  12.         txt = "Hello " + person + "! How are you today?";
  13.     }
  14.     document.getElementById("demo").innerHTML = txt;
  15. }
  16. </script>