Probably a simple question ?

E

EnjoyNews

Hi

Probably a simple question.

How do I write a text in a div while I type it in an input field ?

ex.
I type a text in an input field, and as i type it the text apear in a <div>
right below.

I have found this in the net:
<form name="test" action="">
<input type="text" size="35" name="text"
onkeyup="this.form.return.value=this.value"><br>
<input type="text" readonly size="35" name="return">
</form>

But this return the intire form instead of just the one input field i need.
And it also uses another input field to write it in, where I need it to be
written in a <div>
 
J

jidixuelang

<div id="blackboard">Please input your message!</div>
<input type="text"
onkeyup="document.getElementById('blackboard').innerHTML=this.value;" /
 
E

EnjoyNews

<div id="blackboard">Please input your message!</div>
<input type="text"
onkeyup="document.getElementById('blackboard').innerHTML=this.value;" /

Super :eek:) that was just what I needed

Is it possible to transfer a line change from a text area also ?

So when you make a break in the text area it also makes a break in the <div>
?
 
J

Jeremy J Starcher

<[email protected]> skrev i en meddelelse
news:1956707d-6a69-497b-8bd6-4ef135bcbc35@s37g2000prg.googlegroups.com...
Super :eek:) that was just what I needed

Is it possible to transfer a line change from a text area also ?

So when you make a break in the text area it also makes a break in the
<div> ?

First, a couple of pointers:
The .innerHTML code above may provide unexpected results if someone uses
any of HTML's special characters in your text box.

For instance, try typing
if a < 10 or a > 20.

It is slightly more complicated, but you would be better off creating a
text node and replacing the contents of your 'blackboard.' Google for
createTextNode.

As far as preserving layout:

There are a couple of ways to do this, depending on context.

The easiest way would be to more like
<pre><span id="blackboard"></pre>

The <pre> element was designed for preformatted text and will preserve
both new lines and spaces, however it will give a monospaced font.

I have never tried createTextNode with multiple embedded spaces or new
lines. I may get called on this, but I believe the results would be
undefined.

<URL: http://developer.mozilla.org/en/docs/DOM:document.createTextNode >

is quiet on the subject.
 
S

SAM

EnjoyNews a écrit :
Super :eek:) that was just what I needed

Is it possible to transfer a line change from a text area also ?

So when you make a break in the text area it also makes a break in the <div>


<textarea
onkeyup="var txt = this.value.replace(/[\r\n]/g,'<br>');
document.getElementById('blackboard').innerHTML= txt;">
</textarea>
 
E

EnjoyNews

SAM said:
EnjoyNews a écrit :
Super :eek:) that was just what I needed

Is it possible to transfer a line change from a text area also ?

So when you make a break in the text area it also makes a break in the
<div>


<textarea
onkeyup="var txt = this.value.replace(/[\r\n]/g,'<br>');
document.getElementById('blackboard').innerHTML= txt;">
</textarea>

cool :eek:)

Thanks alot
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top