<input type="button" value="Click me!" onclick="displaymessage()" >
The result is:
If the line: alert("Hello world!!") in the example above had not been put within a function, it would have been executed as soon as the line was loaded. Now, the script is not executed before the user hits the button. We have added an onClick event to the button that will execute the function displaymessage() when the button is clicked.
The syntax for creating a function is:
<!--hide from old browsers
function name (parameter1, parameter2)