<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>JQuery
KeyPress Event in ASP.NET</title>
<script type="text/javascript" language="Javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$("#txtBox").keypress(
function (e) {
if (event.which == 64) {
$("#lblEntered").text("You Have Pressed '@' Sign");
}
else if
(event.which == 35) {
$("#lblEntered").text("You Have Pressed '#' Sign");
}
else if
(event.which == 36) {
$("#lblEntered").text("You Have Pressed '$' Sign");
}
else if (event.which
== 37) {
$("#lblEntered").text("You Have Pressed '%' Sign");
}
else if
(event.which == 38) {
$("#lblEntered").text("You Have Pressed '&' Sign");
}
else if (event.which == 42) {
$("#lblEntered").text("You Have Pressed '*' Sign");
}
else if
(event.which == 43) {
$("#lblEntered").text("You Have Pressed '+' Sign");
}
else if
(event.which >= 65 && event.which <= 90) {
$("#lblEntered").text("You have pressed 'uppercase alphabet
character'");
}
else if
(event.which >= 97 && event.which <= 122) {
$("#lblEntered").text("You have pressed 'lowercase alphabet
character'");
}
else {
$("#lblEntered").text(e.keyCode);
}
}
);
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtBox"
runat="server"></asp:TextBox>
<asp:Label ID="lblEntered"
runat="server"
ForeColor="Red"></asp:Label>
</div>
</form>
</body>
</html>
|
No comments:
Post a Comment