Reputation: 996
I'm using jQuery to retrieve and process a <textarea>
content and process it on the fly. For example:
<textarea id='a'></textarea>
<textarea id='b'></textarea>
<script>
$('#a').keypress(function() {
$('#b').text(this.value);
});
</script>
The problem with this is that it seems that the event fires before the element value changes. Thus, I'm always one character behind.
Is there a way to get the value as it changes?
Upvotes: 0
Views: 199
Reputation: 457
From the documentation of jQuery: http://api.jquery.com/keyup/
The keyup event is sent to an element when the user releases a key on the keyboard.
<textarea id='a'></textarea>
<textarea id='b'></textarea>
<script>
$('#a').keyup(function() {
$('#b').text(this.value);
});
</script>
Upvotes: 2
Reputation: 1124
try .Change() event
<script>
$('#a').Change(function() {
$('#b').text(this.value);
});
</script>
Upvotes: 0
Reputation: 172438
Try using keyup
like this:-
<textarea id='a'></textarea>
<textarea id='b'></textarea>
<script>
$('#a').keyup(function() {
$('#b').text(this.value);
});
</script>
Upvotes: 1