onkeydown Attributeonkeydown Attributeonkeydown is a Common Attribute from the
Events Attribute Collection
and is of Type Script.
It may be used on most elements in the Element Index - all except: base, bdo, br, head, html, meta, param, script, style, title.
The onkeydown attribute is a common attribute which
may be used on most elements to specify script to be executed when the element
has focus and a key is pressed down. This means that it only useful on those
elements which can receive focus (such as text input fields). If the
onkeydown script returns false,
this prevents the user's keystroke from being registered.
See also the onkeypress
and onkeyup attributes.
This site is not intended to act as a scripting reference, so the
precise details of the differences between onkeydown
and onkeypress are not covered here.
If you use this attribute (or any attributes of Type Script) the MIME type of the scripting language used should always be provided in a Content-Script-Type HTTP header.
It is good practice not to use these attributes, however,
and instead to include external scripts (via
script elements)
which add any handlers unobtrusively. This makes code more self-contained and
also the XHTML is easier to maintain if it doesn't contain any events attributes.