Keypress Event




Type anything in below textbox to trigger, keypress event




Sourcode

    Try It Yourself
 
<html>
<head>


<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />


<script type="text/javascript" language="Javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

</head>
<body>


<h2>Keypress Event</h2>
<hr />
<br /><br />

<b>Type anything in below textbox to trigger, keypress event</b><br />
<input id="txtInput" type="text" />

<br /><br />

<script language="javascript" type="text/javascript">
    $(document).ready(function () {

        $("#txtInput").keypress(
            function (event) {

                if (event.which == 64) {
                    alert("You have pressed @ sign");
                }
                else if (event.which == 35) {
                    alert("You have pressed # sign");
                }
                else if (event.which == 36) {
                    alert("You have pressed $ sign");
                }
                else if (event.which == 42) {
                    alert("You have pressed * sign");
                }
                else if (event.which >= 65 && event.which <= 90) {
                    alert("You have pressed uppercase alphabet character");
                }
                else if (event.which >= 97 && event.which <= 122) {
                    alert("You have pressed lowercase alphabet character");
                }

            }
        );

    });
</script>

</body>
</html>
Share with your friends!!