1<!DOCTYPE html>
2<html>
3 <head>
4 <title>Title of the document</title>
5 </head>
6 <body>
7 <p>There is a hidden message for you. Click to see it.</p>
8 <button onclick="myFunction()">Click me!</button>
9 <p id="demo"></p>
10 <script>
11 function myFunction() {
12 document.getElementById("demo").innerHTML = "Hello Dear Visitor!</br> We are happy that you've chosen our website to learn programming languages. We're sure you'll become one of the best programmers in your country. Good luck to you!";
13 }
14 </script>
15 </body>
16</html>
1<script>
2function myFunction() {
3 alert("ALERT THIS FUNCTION HAS RUNNED");
4}
5</script>
6<button onclick="myFunction">click to run function</button>
1 document.getElementById("Save").onclick = function ()
2 {
3 alert("hello");
4 //validation code to see State field is mandatory.
5 }
1// The element id (TheElementID) and var name (myElement) can be named anything.
2var myElement = document.getElementByID('TheElementID');
3myElement.onclick = function() {
4 // Carry out a function here...
5}
1var button = document.querySelector('button');
2button.onclick = function() {
3 //do stuff
4}
1// In HTML:
2// <button id="buttonID" onclick="yourJSFunction()">Text</button>
3
4// In JavaScript:
5function yourJSFunction() {
6 // Do stuff
7 }