Javascript Events
Javascript Events
UNIT 3
JAVSCRIPT
TOPIC:JAVASCRIPT EVENTS
• The change in the state of an object is known as an Event. In html, thereJavaScript
are Events
various
events which represents that some activity is performed by the user or by the browser.
• When javascript code is included in HTML, js react over these events and allow the
execution.
• This process of reacting over the events is called Event Handling. Thus, js handles the
HTML events via Event Handlers.For example, when a user clicks over the browser, add
js code, which will execute the task to be performed on the event.
Keydown & Keyup onkeydown & onkeyup When the user press and then
release the key
Form events:
Event Performed Event Handler Description
<html>
<head> Javascript Events </head>
<body>
<script language="Javascript" type="text/Javascript">
<!--
function clickevent()
{
document.write(“welcome");
}
//-->
</script>
<form>
<input type="button" onclick="clickevent()" value="Who's this?"/>
</form>
</body>
</html>
MouseOver Event
<html>
<head>
<h1> Javascript Events </h1>
</head>
<body>
<script language="Javascript" type="text/Javascript">
<!--
function mouseoverevent()
{
alert("welcome");
}
//-->
</script>
<p onmouseover="mouseoverevent()"> Keep cursor over me</p>
</body>
</html>
Keydown Event
<html>
<head> Javascript Events</head>
<body>
<h2> Enter something here</h2>
<input type="text" id="input1" onkeydown="keydownevent()"/>
<script>
<!--
function keydownevent()
{
document.getElementById("input1");
alert("Pressed a key");
}
//-->
</script>
</body>
</html>
Load event
<html>
<head>Javascript Events</head>
</br>
<body onload="window.alert('Page
successfully loaded');">
<script>
<!--
document.write("The page is
loaded successfully");
//-->
</script>
</body>
</html>
Focus Event
<html>
<head> Javascript Events</head>
<body>
<h2> Enter something here</h2>
<input type="text" id="input1"
onfocus="focusevent()"/>
<script>
<!--
function focusevent()
{
document.getElementById("input1").style.ba
ckground=" aqua";
}
//-->
</script>
</body>
</html>
Test it Now