Diffrence between KeyCode & CharCode in JavaScript OR KeyCode Vs CharCode in JavaScript. [Resolved]

Posted by Tsurendra690-29180 under JavaScript on 12/11/2015 | Points: 10 | Views : 8523 | Status : [Member] | Replies : 2
Can any one of you explain the difference between Keycode & Charcode (KeyCode Vs CharCode) in JavaScript, and how those two are useful?




Responses

Posted by: Sheonarayan on: 12/11/2015 [Administrator] HonoraryPlatinum | Points: 50

Up
1
Down

Resolved
There are two types of keyboard codes

1. Keyboard code (keyCode) - is a number that represents the key on the keyboard when user presses the key

2. Character code (charcode) - a number that represents the unicode character of the key on keyboard when user presses the key

Below are the JavaScript functions that will help you to get the keyCode and charCode in JavaScript.

<script>
// get key code
function getKey(event) {
event = event || window.event;
var keyCode = event.which || event.keyCode;
alert(keyCode);
}
// get char code
function getChar(event) {
event = event || window.event;
var keyCode = event.which || event.keyCode;
var typedChar = String.fromCharCode(keyCode);
alert(typedChar);
}
</script>


Look at the live example here http://techfunda.com/Examples/Show?exampleid=612.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Tsurendra690-29180, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 12/11/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
please refer: http://stackoverflow.com/questions/1444477/keycode-and-charcode

--
Thanks & Regards,
RNA Team

Tsurendra690-29180, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response