You should search about events. In your case the click
event to be specific. You have to handle the button's click event, like this:
<input type="button" value="Click Me" id="myButton" />
Then the script:
document.getElementById("myButton").onclick = function()
{
window.alert("Hi there!");
}
Demo.
This is the simpler way of doing this. Here's some references for further information:
Good luck.