Vicky
Vicky

Reputation: 829

In Javascript onkeypress Event,Tab button does not fire(In Mozilla Firefox)

I have a textbox, I need to validate my textbox using onkeypress (to restrict special characters). It works fine in Chrome. In Mozilla Firefox it does not fire (Tab Button). Is there any events to add in my code?

My code:

function alpha(e) {
    var k;
    document.all ? k = e.keyCode : k = e.which;
    return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 9);   //k=9(keycode for tab)
}

Upvotes: 0

Views: 672

Answers (2)

Andolasoft Inc
Andolasoft Inc

Reputation: 1296

This might help you.

function alpha(e){
    var k = e.charCode ? e.charCode : e.keyCode;
    return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 9);   //k=9(keycode for tab)
}

Upvotes: 1

Ashwini Verma
Ashwini Verma

Reputation: 7525

test this code

function alpha(e) {
    var code = e.keyCode || e.which;
    if(code == 9) { //Tab keycode
      //Do something
    }
}

Upvotes: 1

Related Questions