Reputation: 641
I am trying to only allow the user to input numeric characters in a textbox however when I run the program it says
Unhandled exception at line 310, column 1 in Function code
0x800a138f - Microsoft JScript runtime error: Object expected
It highlights keypresshandler(event).
Heres my code:
jquery.js
function myFunction() {
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
e.preventDefault();
}
}
Default.aspx
<asp:TextBox ID="SortOrderTextBox" runat="server" Height="10px" Text='<%# Eval("SortOrder") %>' Font-Size="Small"/>
<input type="text" onkeydown="myFunction()" />
Upvotes: 0
Views: 94
Reputation: 544
This works for you:
<input type="text" onkeypress="myFunction()">
Change myFunction() to your function name, or whatever you're having it do.
Upvotes: 1