Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

keycode 13 and keycode 10 not working

Event keypress 13 and 10 not working on iPhone safari, android firefox but working with android default browser.

I have a jsp page which has a form which that takes a number as input and changes values of other div elements in the same page by dividing those numbers by this input.

I am using keypress function of jQuery and testing with keycode 10 and 13 for this. It's working on all desktop browsers but the GO button doesn't fire on safari and firefox on smart phones. Please let me know how to go about this?

Here is the partial code I have used:

$('.number').keypress(function(e) {
    if(e.keyCode == 10 || e.keyCode == 13 ) {

        $('#1').html((textreplace/input).toFixed(0)+'g');
        $('#2').html((textreplace2/input).toFixed(0)+'%');
        $('#3').html((textreplace3/input).toFixed(0)+'g');
        ...
        ..

    }
}

The ".number" is the class name used in the input form which has type="text". So, basically I am not using submit at all.

like image 633
Srinivas Avatar asked Aug 11 '11 15:08

Srinivas


People also ask

What is e keyCode === 13?

Keycode 13 is the Enter key.

Why is keyCode deprecated?

KeyCode was deprecated because in practice it was “inconsistent across platforms and even the same implementation on different operating systems or using different localizations.” The new recommendation is to use key or code .

What can I use instead of keyCode?

Note: The keyCode property is deprecated. Use the key property instead.

Does Keydown work on mobile?

It works on computers, but not on mobile.. EDIT: I need to get the keyCode when a key is pressed...


1 Answers

Try using keyup and keydown. keypress event is not really ideal.

like image 189
Caimen Avatar answered Oct 01 '22 06:10

Caimen