Solved

Display text on website using a textbox with jQuery

Posted on 2012-12-27
4
380 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn how to dynamically set the form action using jQuery.
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)

828 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