First of all, how do you define "when the user finishes writing"?
If you're just looking to echo the contents of the input
to another element, you can do that as-the-user-types by binding to the keyup
event. Using jQuery it might look something like this:
$('input[name="username"]').keyup(function (e) {
$('#output').text($(this).val());
});
What this would do is any time a key is pressed in the input
of name "username", the text in an element of id
"output" would be updated with the current value of that input
. So, of course, you'd need some kind of element with an id
of "output":
<span id="output"></span>
If you don't want this to happen as-they-type but instead want to wait until the user presses the return key, you'd still use the same event. You'd just check which key was pressed in the event and only update the text if it was the return key:
$('input[name="username"]').keyup(function (e) {
if (e.keyCode == 13) {
$('#output').text($(this).val());
}
});