Display text on website using a textbox with jQuery

ats2012
ats2012 used Ask the Experts™
on
I have some code where you type some text in a textbox and it will display under it. What i would like is instead of using keypress I am looking for it copying the text box so right now when you back space it wont delete it until you press another key. Is this possible? Below is the code I am using.

<!DOCTYPE html>

<html>
<head>
<script src="jquery.js" language="javascript" type="text/javascript"></script>
<title>Display text</title>

</head>

<body>

<input type="text" value="" id="box"/>
<div id="div_one"></div>



<script>
$("#box").keypress(function() {
    var $this= $(this);
    window.setTimeout(function() {
       $("#div_one").text($this.val());
    }, 0);
});
</script>

</body>

</html>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Use onkeyup, eg try this

<p><input type="text" onkeyup="document.getElementById('myDiv').innerHTML=this.value"> </p>
<div id="myDiv"></div>

Open in new window

Author

Commented:
This is what I was looking for. Thanks

Author

Commented:
There a fix for Internet Explorer? It works great in Chrome but all my users will be using IE.

Author

Commented:
Nevermind I got it working

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial