How to fire JavaScript and JQuery in Textbox Keypress event

Posted by Jayakumars under ASP.NET AJAX category on | Points: 40 | Views : 6493
I have post the code for How to fire JavaScript and JQuery in Textbox Keypress event.

Client Side Code.

<html xmlns="">
<head runat="server">
<script language ="javascript" src="Scripts/jquery-1.4.1.js"></script>
<script language ="javascript" src="Scripts/jquery-1.4.1.min.js"></script>

<script type="text/javascript" language="javascript">
function validateNumbersOnly(e) {
var unicode = e.charCode ? e.charCode : e.keyCode;
if ((unicode == 8) || (unicode == 9) || (unicode > 47 && unicode < 58)) {
return true;
else {
window.alert("This field accepts only Numbers");
return false;

$(document).ready(function () {
$("#TextBox2").keypress(function () {
alert('Check this');


<form id="form1" runat="server">
Asp TextBox : <asp:TextBox ID="numericTextBox" runat="server" onkeypress="return validateNumbersOnly(event);"></asp:TextBox> <br />
Html Control: <input id="txtName" runat="server" maxlength="32" onkeypress="return validateNumbersOnly(event);"> <br />
JQuery TextBox : <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>


Comments or Responses

Posted by: Hariinakoti on: 10/17/2012 Level:Starter | Status: [Member] | Points: 10
Hello JayaKumar,
It is Working in Javascript but it is not working in jquery.I added .Js file also.Please check it edit ur post.
Posted by: Jayakumars on: 10/17/2012 Level:Bronze | Status: [Member] [MVP] | Points: 10

are u working in this code? which browser? working good for me
see this image
Posted by: Hariinakoti on: 10/18/2012 Level:Starter | Status: [Member] | Points: 10
Hello JayaKumar,
i'm using ie8 and google chrome,firefox.Jquery code is working for alert message is accepting characters also .But javascript code is working very well.

Login to post response