Click here to Skip to main content
15,441,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

i have a javascript code like below,

C#
if (event.keycode != 37 && event.keycode != 39)
{
    var phoneNumber = $("#phoneNumber").val();
    if (phoneNumber.length < 1 && event.keyCode != 48)
        $("#phoneNumber").val(0)
    else if ((phoneNumber.length < 2 && event.keyCode == 48) )
        event.preventDefault();
    else
        $("#phoneNumber").val(phoneNumber)
}


keycode 37 = left arrow, keycode 39 = right arrow but when i pressed these keys on keyboard condition which is between if block being executed, i am using chrome browser, also i used the if statement below,

C#
if (event.keycode != 37 || event.keycode != 39)
{
    var phoneNumber = $("#phoneNumber").val();
    if (phoneNumber.length < 1 && event.keyCode != 48)
        $("#phoneNumber").val(0)
    else if ((phoneNumber.length < 2 && event.keyCode == 48) )
        event.preventDefault();
    else
        $("#phoneNumber").val(phoneNumber)
}


urgent helps greatly appreciated,

Thanks everybody.
Posted
Comments
Irbaz Haider Hashmi 6-Feb-13 7:30am    
keyCode - C Uppercase
bounik 6-Feb-13 8:25am    
Thanks Irbaz, this helped me so much!
Irbaz Haider Hashmi 6-Feb-13 8:40am    
you are welcome
Irbaz Haider Hashmi 6-Feb-13 8:42am    
I just figured out that i posted in comment. I am posting as solution so others can see it.
Ankur\m/ 6-Feb-13 7:42am    
How are you calling it?

1 solution

keyCode

In keyCode "C" should be upper case.
 
Share this answer
 
Comments
Ankur\m/ 6-Feb-13 8:53am    
5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900