Friday, December 28, 2012

onkeypress

Event handler onkeypress terjadi ketika suatu key pada keyboard dalam kondisi tertekan ke bawah.

Berikut contoh meregister event handler onkeypress via 'inline model':

<FORM> Tulis nama Anda: <INPUT TYPE="text" ONKEYPRESS="this.style.background='yellow'"> </FORM>

Berikut contoh meregister event handler onkeypress 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").onkeypress=HandleEvent; </SCRIPT>

Berikut contoh meregister event handler onkeypress 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("keypress", HandleEvent, false); </SCRIPT>