Monday, August 18, 2014

Key up and Key down in jquery : example

Below html code creates a input type field which is handled with jquery code.

<!DOCTYPE html>
<html>
<head><title>Key Up down example in jquery</title></head>
<body>


<input type="text" id="user_text"><br/>
<span id="user_text_feedback"></span>

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="key_up_down.js"></script>
</body>
</html>

//key_up_down.js
//keyup is to show all variable of input box on key up
$('#user_text').keyup(function(){
var user_text = $('#user_text').val();
$('#user_text_feedback').html(user_text);
});

//similarly for keydown
//keydown is to show variable of input box except last one.
// $('#user_text').keydown(function(){
// var user_text = $('#user_text').val();
// $('#user_text_feedback').html(user_text);
// });

No comments:

Post a Comment