Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am having a js file which is called for integer entry in textbox as follows:
C#
function Numeric_Text_KeyDown(event)
{
    var iKeyCode = event.keyCode;
    //alert(iKeyCode);
    if ( (event.ctrlKey) || (event.altKey)) return false;

    if (iKeyCode == 38 || iKeyCode == 40 || iKeyCode == 13 || iKeyCode == 9 ||
    iKeyCode == 8 || iKeyCode == 46 ||iKeyCode == 39 ||iKeyCode == 37 ||
    iKeyCode == 229 ||((iKeyCode > 47 && iKeyCode < 58) && !(event.shiftKey) ) ||
    (iKeyCode > 111 && iKeyCode < 124) ||(iKeyCode > 95 && iKeyCode < 106))
    {

        if (iKeyCode == 38 || iKeyCode == 40 || iKeyCode == 13 || iKeyCode == 9) {
            return true;
        }
        else if((iKeyCode > 47) && (iKeyCode < 58)){
            return true;
        }
    }
    else
    {
    return false;
    }
}

In source referred js file as
<script language="javascript" type="text/javascript" src="../JS/Common.js"></script>
Code behind
FtxtDate.Attributes.Add("onkeydown", "return NumericText_KeyDown(event);");

But Validation for integer in textbox not working.
Posted

1 solution

There is not any bug on your code. I can run your code very perfectly. The error can be in another javascript so that its not working.
 
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