user796443
user796443

Reputation:

why result of `charCodeAt(0)` and `e.keyCode` don't match?

Any ideas why result of charCodeAt(0) and e.keyCode don't match? and how do I fix this situation?

var stop_symbols = $("#words_stop_symbols span").text().split('').map(function (val) {return val.charCodeAt(0);});
    console.dir(stop_symbols);
    //
    $(document).on("keydown", ".quick-edit", function(e) {
        console.dir(e.keyCode);
        if ($.inArray(e.keyCode,stop_symbols) != -1) {
            // 
            console.dir("blocked char")
            return false;
        }
    });

Upvotes: 2

Views: 340

Answers (1)

adeneo
adeneo

Reputation: 318252

Using the keypress event will work :

$(document).on("keypress", ".quick-edit", function (e) {
    if ($.inArray(e.keyCode, stop_symbols) != -1) {
        return false;
    }
});

FIDDLE

Upvotes: 1

Related Questions