Why is event key code different in onkeydown, onkeyup vs onkeypress

by Javascript Specialist August 7, 2014 12:19

1. onkeydown and onkeyup stores the physical key.

2. onkeypress stores the key being typed.

So if you type the lowercase letter 'a', 
i. using onkeypress, you will get the key code 65
ii. using onkeyup, onkeydown, you will get the capital letter 'A' key code, 97 because the physical key is a capital A.

Why we would want to ever care to know the physical key? Sometimes the programmers drink too much.

To test these scenarios out, refer to this link:

JavaScript | Questions and Answers

What is the difference between keycode and charcode vs which?

by Javascript Specialist August 7, 2014 12:02

1. The key you type is stored in either event.keycode or  event.charcode depending on the browser you are using.

2. With current browsers, event.which property normalizes the event.keycode and event.charcode so that you do not have to worry. However, event.which is not supported on IE8 and older.

3. My recommendation is to get the correct event is to use this javascript code:

var chCode = ('charCode' in event) ? event.charCode : event.keyCode;

This code is supported in all browsers in all version include IE8.

This coding is saying if charCode exist int he event, the use charCode else use keyCode.

JavaScript | Questions and Answers

What is the difference between UL vs OL?

by Javascript Specialist August 6, 2014 21:43
UL = "unordered list". UL, by default, displays bullets.
OL ="ordered list". OL, by default displays numbers.

Other than that, there is no difference. You can use style attribute to modify the default formats.

Historically, there was no CSS. So there wasn't any way to customize the list formats such as margins, and display types. Now, CSS provides this capability and so it is really not necessary to know both tags. 

Questions and Answers | HTML

Get Keycode

by Javascript Specialist August 7, 2014 12:22
Every now and then, when you develop with JavaScript, you will need to know the key Code of what your user is typing:

Key Code example:
EventAscii Keyback to Char

For an explanation as to why these keys are the way they are, refer to this link 

JavaScript | References