run a function when a button has the onclick
snippet in html

run a function when a button has the onclick

user996

<script>
function myFunction() {
  alert("ALERT THIS FUNCTION HAS RUNNED");
}
</script>
<button onclick="myFunction">click to run function</button>

javascript onclick

user4496

 document.getElementById("Save").onclick = function ()
    {
     alert("hello");
     //validation code to see State field is mandatory.  
    }

how to add onclick event in javascript

user2332

var element = document.getElementById("elem");
element.onclick = function(event) {
  console.log(event);
}

button functions html

user6652

<script>
 function myFunction() {
   alert("ALERT");
 }
</script>
<button onclick="myFunction">Click</button>

calling function on click html

user4438

  <img src="hospital.png" id="hospitals" onclick="damarkers();">