Rápli András
Rápli András

Reputation: 3923

jQuery keyup character error

I'm getting strange characters when the keyup event is fired. For example pressing - shows up as ½ on screen.

$('#c').append(String.fromCharCode(e.which).toLowerCase());

What should I do?

Upvotes: 1

Views: 116

Answers (1)

adeneo
adeneo

Reputation: 318182

You need to use the keypress event, not the keyup or keydown events, as those would cause this exact problem.

change :

$('#a').on('keyup', function(e) {
    $('#c').append(String.fromCharCode(e.which).toLowerCase());
});

FIDDLE

to :

$('#a').on('keypress', function(e) {
    $('#c').append(String.fromCharCode(e.which).toLowerCase());
});

FIDDLE

Upvotes: 2

Related Questions