简体   繁体   中英

Arrow keys not working in firefox with given javascript

I have one textbox coded like below :

<input name="txttelephone" type="text" maxlength="16" id="txttelephone" class="InputTextBox" onkeypress="return NumbersOnly(event);" required />

And javascript function is like below :

function NumbersOnly(e) {
    var unicode = e.charCode ? e.charCode : e.keyCode;
    if (unicode != 8) {
        if (unicode < 48 || unicode > 57) {

            if (unicode == 9)
                return true;
            else
                return false;
        }
    }
}

Now When I run this in chrome arrow keys working proper but in firefox arrow key is not working. Not getting what is the issue.

Please help me with this.

Thanks,

Dipa

You have to exclude arrow key codes. Try following modification in your code.

function NumbersOnly(e) {
    var unicode = e.charCode ? e.charCode : e.keyCode;
    if (unicode != 8) {
        if (unicode < 48 || unicode > 57) {

            if (unicode == 9 || IsArrows(e) )
                return true;
            else
                return false;
        }
    }
}
function IsArrows (e) {
       return (e.keyCode >= 37 && e.keyCode <= 40); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM