When your users visit your website, they do things like click on things, hover over things etc. These are examples of what JavaScript calls events. Using JavaScript, you can respond to an event using Event Handlers. You can attach an event handler to the HTML element for which you want to respond to when a specific event occurs. For example, you could attach JavaScript's onMouseover event handler to a button and specify some JavaScript to run whenever this event occurs against that button.
Window Events
onload : Fires after the page is finished loading
onunload : Fires once a page has unloaded (or the browser window has been closed)
Form Events
onblur - Fires the moment that the element loses focus.
onchange - Fires the moment when the value of the element is changed
onfocus - Fires the moment when the element gets focus
onselect - Fires after some text has been selected in an element.
<script type="text/javascript">
function getValue(){
alert(document.getElementById('select1').value);
}
</script>
Key Events
onkeydown - Fires when a user is pressing a key
onkeypress - Fires when a user presses a key
onkeyup - Fires when a user releases a key
Uses :Event handler for TextField, Textarea
Example :
Demo of onKeyUp
<script type="text/javascript">
function getTextvalue(){
alert(document.getElementById('text1').value);
}
</script>
Mouse Events
onclick : Fires on a mouse click on the element onmouseover : Executes JavaScript code when the user takes the mouse over onmousemove : Executes JavaScript code when the user moves the mouse onmouseout : Executes JavaScript code when the user takes the mouse out