Jquery textbox KeyUp event

Jquery textbox KeyUp event

Jquery keypress event. Here we will see how to to get keycode and text when user press the key. we need to attach Jquery keyup event to textbox.

$("#Text1").keyup(function(e){}

Above code snippet finds input control by Id “Text1” and attach keyup event to it.

var keycode = e.KeyCode ? e.KeyCode : e.which ;

In IE you can get the value of keycode by using “e.KeyCode” but for FireFox it is “e.which”.

So, be careful while using e.KeyCode.

Jquery to get Key Pressed value.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

   <script type="text/javascript" language="javascript">
   
   $(document).ready( function (){ 
   
       $("#Text1").keyup(function(e){
       
       var key = $(this).val();
       
       var keycode = e.KeyCode ? e.KeyCode : e.which ;
       
       var message = key + " " + keycode;
       
       $("#msg").text( message );
       
       });
                       
    });
   
   </script>

Html code for keyup event

<div>
        
        <input id="Text1" type="text" />    
        <label id="msg"></label>
        </div>

The same way you can trap the key as soon as it is pressed using keydown event, You can also use keypress() event instead of keyup event to trap the key.

In above example we are finding the key pressed by user inside the input textbox. we are displaying the value of key along with key code inside label control.

You can also trap escape and print screen keys and take appropriate actions.

Tags:

JQuery Set Value of Textbox or Label Control In Asp.netGridview select emailLearning JqueryBasics of jqueryJQuery TextBox Value()Jquery Set Value Of Textbox.Jquery button click eventJquery image click eventJquery Get Target Of EventJQuery SlideJquery Trim String

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.