Producing web pages
* HTML CSS DHTML XHTML A to Z of tags        Accessibility          Design

Common scripting events

There are a number of HTML attributes that define scripting events. The attribute value is a script (typically a function call or a few short statements) that the browser executes when the event occurs.

The available events are as follows:

  • onclick. Takes place when you click the mouse on a tag. You could use it to display a page in a new window when you click on a link.
  • ondblclick. Takes place when you double-click the mouse on a tag
  • onkeydown. Takes place when you press a key
  • onkeypress. Takes place when you press an alphanumeric key
  • onkeyup. Takes place when you release a key
  • onmousedown. Takes place when you press the mouse button over a tag
  • onmouseup. Takes place when you release the mouse button over a tag
  • onmouseover. Takes place when you when move the mouse onto a tag. You can use it to get a message to appear in the status bar of the browser window when you move the mouse over a link
  • onmousemove. Takes place when you move the mouse over a tag
  • onmouseout. Takes place when you moved the mouse away from a tag
  • onload. Takes place when the browser finishes loading a window or frames. You use this event with the <body> or <frameset> tags
  • onunload. Takes place when the browser finishes unloading a window or frames. You use this event with the <body> or <frameset> tags
  • onfocus. Takes place when a tag recives the focus either by pointing at it with the mouse or tabbing to it. You use this event with the <label>, <input>, <select>, <textarea> or <button> tags
  • onblur. Takes place a tag loses the focus. You use this event with the <label>, <input>, <select>, <textarea> or <button> tags
  • onsubmit. Takes place a user submits a form. You only use this event with the <form> tag
  • onreset. Takes place a user resets a form. You only use this event with the <form> tag
  • onselect. Takes place when a uses selects some text in a text field. You use this event with the <input> and <textarea>tags
  • onchange. Takes place when a tag loses focus and the user has changed the value. You use this event with the <input>, <select> and <textarea> tags

If you use an event attribute, you must specify a default scripting language for the document. For example:

<meta http-equiv="Content-Script-Type" 
content="text/javascript">