15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 13 ✦ Event Objects (Chapter 29)<br />

Listing 29-16: Displaying keyCode Property Values<br />

<br />

<br />

keyCode Property<br />

<br />

TD {text-align:center}<br />

<br />

<br />

function showCode(which) {<br />

document.forms[0].elements[which].value = event.keyCode<br />

}<br />

function clearEm() {<br />

for (var i = 1; i < document.forms[0].elements.length; i++) {<br />

document.forms[0].elements[i].value = “”<br />

}<br />

}<br />

<br />

<br />

<br />

keyCode Property<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Eventevent.keyCode<br />

onKeyDown:<br />

onKeyPress:<br />

onKeyUp:<br />

<br />

<br />

<br />

<br />

The following are some specific tasks to try with the page to examine key codes<br />

(if you are not using a browser set for English and a Latin-based keyboard, your<br />

results may vary):<br />

1. Enter a lowercase letter “a”. Notice how the onKeyPress event handler shows<br />

the code to be 97, which is the Unicode (and ASCII) value for the first of the<br />

lowercase letters of the Latin alphabet. But the other two events record just<br />

the key’s code: 65.<br />

2. Type an uppercase “A” via the Shift key. If you watch closely, you see that the<br />

Shift key, itself, generates the code 16 for the onKeyDown and onKeyUp events.<br />

419<br />

(IE) event.keyCode

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!