Home / code / javascript

Event handlers in Javascript

JavaScript applications in browsers are largely event-driven. Events are actions that usually occur as a result of something the user does. For example, clicking a button is an event,as is changing a text field or moving the mouse over a link. For a script to react to an event, you define eventhandlers, such as onChange and onClick.

Event Applies to Occurs when Event handler
Abort images User aborts the loading of an image (for example by clicking a link or clicking the Stopbutton) onAbort
Blur windows and all form elements User removes input focus from window or form element onBlur
Change text fields,textareas, select lists user changes value of element onChange
Click buttons, radio buttons, checkboxes, submit buttons, reset buttons, links User clicks form element or link onClick
DragDrop windows User drops an object onto the browser window, such as dropping a file on the browser window onDragDrop
Error images, windows The loading of a document or image causes an error onError
Focus windows and all form elements User gives input focus to window or form element onFocus
KeyDown document, images, links text areas User depresses a key onKeyDown
KeyPress documents, images, links, text areas User presses or holds down a key onKeyPress
KeyUp documents,images, links, text areas User releases a key onKeyUp
Load document body User loads the page in the browser onLoad
MouseDown documents, buttons, links User depresses a mouse button onMouseDown
MouseMove nothing by default User moves the cursor onMouseOut
MouseOut areas, links User moves cursor out of a client-side image map or link onMouseOut
MouseOver links User moves a cursor over a link onMouseOver
MouseUp documents, buttons, links User releases a mouse button onMouseUp
Move windows User or script moves a window onMove
Reset forms User resets a form (clicks a reset button) onReset
Resize windows User or script resizes a window onResize
Select text fields, textareas User selects form elements input field onSelect
Submit forms User submits a form onSubmit
Unload document body User exits the page onUnload

Example, of a script that calculates an expression and shows the value in a textfield

<HTML>
<HEAD>
<SCRIPT>
<!-- start
function calculate(f)
{
  if (confirm("Are you sure?"))
	f.result.value = eval(f.expressie.value)
  else
	alert("Try again")
}
// end -->
</SCRIPT>
</HEAD>
<BODY>
<FORM>
Type an expression:
<INPUT type="text" name="expressie" size=15>
<INPUT type="button" value="Calculate" onClick="calculate(this.form)">
<BR>
Result:
<INPUT type="text" name="result" size=15>
</BODY>
</HTML>

If you want more info click here.

 

TOP

Latest script:

 

Books: