Click here to Skip to main content
15,868,292 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have textbox in my aspx page.
its allow the alphabets and backspace button is working fine but tab key is not working. my script like this

C#
function AllowAlphabet(e) {
              isIE = document.all ? 1 : 0
              keyEntry = !isIE ? e.which : event.keyCode;
              if (((keyEntry >= '65') && (keyEntry <= '90')) || ((keyEntry >= '97') && (keyEntry <= '122')) || (keyEntry == '46') || keyEntry == '8' || keyEntry == '9')
                  return true;
              else
                  return false;
          }

<asp:TextBox ID="txtempfirstname" runat="server" class="textbox" TabIndex="1" align="right" onkeypress="return AllowAlphabet(event)">

but tab key not working.. please help me

thanks
Posted
Updated 18-Mar-13 23:05pm
v2

Hi,

You can catch whether a TAB key was pressed in following way,

HTML
<html>
<head>

</head>
<body>

<script type="text/javascript">
function AllowAlphabet(e) 
{
    if (event.keyCode == 9) 
    {
        //TAB is pressed keyCode = 9 for TAB key
        return false;
    }
    else
    {
        return true;
    }
}
</script>

<input type="text" id="txtName" onkeydown="return AllowAlphabet(event)">
</body>
</html>


Please check the difference in your code and one I have put here is mostly I have used onkeydown event where you used a onkeypress event.

Let me know if that helps you.
 
Share this answer
 
Try this code !!


C#
function AllowAlphabet(e) {
           keyEntry = (e.keyCode) ? e.keyCode : e.which;
           if (((keyEntry >= '65') && (keyEntry <= '90')) || ((keyEntry >= '97') && (keyEntry <= '122')) || (keyEntry == '46') || keyEntry == '8' || keyEntry == '9')
               return true;
           else
               return false;
       }</script>
 
Share this answer
 

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