ISMA309


Event handlers

by Haig. Average Reading Time: less than a minute.

An event handler can be considered a trigger that executes code when something happens, in the ‘event’ of a click or move your mouse over a link, submit a form etc.

onClick

onClick handlers execute something only when users click on buttons, links, etc. Let’s see an example:

	<html>
		<script>
			function specialsauce() {
				alert("Thank you!")
				}
		</script>
		<form>
			<input type="button" value="Click here" onclick="specialsauce()">
		</form>
	</html>

The function specialsauce() is invoked when the user clicks the button. Note: Event handlers are not added inside the <script> tags, but rather, inside the html tags.

onLoad

The onload event handler is used to call the execution of JavaScript after loading:

	<body onload="ss()">
		<frameset onload="ss()">
		<img src="whatever.gif" onload="ss()">
	</body>

No comments on ‘Event handlers’

Leave a Reply