Newokmyne
Newokmyne

Reputation: 65

get the keycode value - javascript

I am trying to get the pressed key value but ... no result or it outputs "undefined". Here's the code:

    <body onkeypress="checkLetter(e)" >
    </body>

    <script>
        function checkLetter(e)
        {
            var mot = "aracnophobie";
            var lettre = String.fromCharCode(e.keyCode);
            alert(lettre);
        }
    </script>

Can someone help please?

Upvotes: 0

Views: 42

Answers (1)

ad_revenge
ad_revenge

Reputation: 101

I'm not sure about you're trying to do, but test it with an "event" param, not "e" : onclick="checkLetter(event)"

Upvotes: 1

Related Questions