Css Exp - 8 - 20203B1002
Css Exp - 8 - 20203B1002
Resources required:
Hardware Software
Practical Significance:
A JavaScript executes in response to an event that occurs while a form is displayed on
the screen. An event is something the user does to the form, such as clicking a button,
selecting a radio button, or moving the cursor away from an element on the form. The
browser also fires events when the page finishes loading from the server.
Theoretical Background
When you interact with the keyboard, the keyboard events are fired. There are three
main keyboard events:
keydown – fires when you press a key on the keyboard and it fires repeatedly while
you holding down the key. keyup – fires when you release a key on the keyboard.
keypress – fires when you press a character keyboard like a,b, or c, not the left arrow
key, home, or end keyboard, … The keypress also fires repeatedly while you hold
down the key on the keyboard.
The keyboard events typically fire on the text box, through all elements support
them.
When you press a character key once on the keyboard, three keyboard events are
fired in the following order:
keydown
keypress keyup
Both keydown and keypress events are fired before any change made to the text box,
whereas the keyup event fires after the changes have made to the text box. If you
hold down a character key, the keydown and keypress are fired repeatedly until you
release the key.
When you press a non-character key, the keydown event is fired first followed by the
keyup event. If you hold down the non-character key, the keydown is fired repeatedly
until you release the key.
First, select the element on which the keyboard event will fire. Typically, it is a text
box.
Suppose that you have the following text box with the id message:
Example:
<html>
<head><title>Javascript Form Events : onClick Event</title>
<script>
function Japan(){
alert("konnichiwa");
}
function India(){
alert("namaste");
}
function Germany(){
alert("Guten Tag");
}
</script>
</head>
<body>
<p>Hello in Different Countries</p>
<form>
<input type="button" value="Japan"
onclick ="Japan()" />
</body>
</html>
Practice Questions
a. onblur
b. onfocus
c. onselect
d. onchange
a. onblur
b. onfocus
c. onselect
d. onchange
a. True
b. False
Exercise: