Event handler onkeydown
(Bubbles: Yes, Cancelable: Yes) terjadi ketika suatu key pada keyboard dalam kondisi tertekan ke bawah.
Berikut contoh meregister event handler onkeydown
via 'inline model':
<FORM>
Tulis nama Anda:
<INPUT TYPE="text" ONKEYDOWN="this.style.background='yellow'">
</FORM>
Berikut contoh meregister event handler onkeydown
via 'traditional model':
<FORM>
Tulis nama Anda:
<INPUT TYPE="text" ID="inputTextID">
</FORM>
<SCRIPT TYPE="text/javascript">
function HandleEvent()
{
this.style.background="yellow";
}
document.getElementById("inputTextID").onkeydown=HandleEvent;
</SCRIPT>
Berikut contoh meregister event handler onkeydown
via DOM:
<FORM>
Tulis nama Anda:
<INPUT TYPE="text" ID="inputTextID">
</FORM>
<SCRIPT TYPE="text/javascript">
function HandleEvent()
{
this.style.background="yellow";
}
var inputElem=document.getElementById("inputTextID");
inputElem.addEventListener("keydown", HandleEvent, false);
</SCRIPT>