Solved

Display text on website using a textbox with jQuery

Posted on 2012-12-27
4
376 Views
Last Modified: 2012-12-28
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

0
Comment
Question by:ats2012
  • 3
4 Comments
 
LVL 31

Accepted Solution

by:
GwynforWeb earned 500 total points
ID: 38725091
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

0
 

Author Closing Comment

by:ats2012
ID: 38725104
This is what I was looking for. Thanks
0
 

Author Comment

by:ats2012
ID: 38726866
There a fix for Internet Explorer? It works great in Chrome but all my users will be using IE.
0
 

Author Comment

by:ats2012
ID: 38726877
Nevermind I got it working
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now