How to real time display input value with jQuery?
-
05-07-2019 - |
Question
<input type="text" id="name" />
<span id="display"></span>
So that when user enter something inside "#name",will show it in "#display"
OTHER TIPS
A realtime fancy solution for jquery >= 1.9
$("#input-id").on("change keyup paste", function(){
dosomething();
})
if you also want to detect "click" event, just:
$("#input-id").on("change keyup paste click", function(){
dosomething();
})
if your jquery <=1.4, just use "live" instead of "on".
$('#name').keyup(function() {
$('#display').text($(this).val());
});
The previous answers are, of course, correct. I would only add that you may want to prefer to use the keydown
event because the changes will appear sooner:
$('#name').keydown(function() {
$('#display').text($(this).val());
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow