473,699 Members | 2,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to display TextArea value in <Span> innerHTML with <br> in Netscape

xhe
I met a very headache problem in javascript, I think this might be
difference between IE and NS / Safari.

I have a text area
<form>
<textarea name='tex1' onkeyup='displa yit();'></textarea>
</form>
<span id="txtValue"> </span>

<script language='javas cript'>
function displayit()
{

document.getEle mentById("txtVa lue").innerHTML =document.forms[0].tex1.value;
}
</script>

This is a very simple program.
When I run in IE, and no problem, line break in the textares changed
to <brin the span tag, and line changed automatically.
Problem here is when I run it in Netscape and Safari, the line break
in textarea does not change to <br>, and all the text in the textares
are displayed in one paragraph.

Can anyone tell me how to display the multi-line paragraph contents
of the textarea in the <spaninnerHTM L correctly to have <br>
there? This is only for NS and Safari. Maybe this is their bugs?

Thanks.
Please email me at he******@gmail. com

Feb 7 '07 #1
2 19578
On Feb 7, 3:27 pm, "xhe" <hexuf...@gmail .comwrote:
I met a very headache problem in javascript, I think this might be
difference between IE and NS / Safari.

I have a text area
<form>
<textarea name='tex1' onkeyup='displa yit();'></textarea>
</form>
<span id="txtValue"> </span>

<script language='javas cript'>
function displayit()
{

document.getEle mentById("txtVa lue").innerHTML =document.forms[0].tex1.value;}

</script>

This is a very simple program.
When I run in IE, and no problem, line break in the textares changed
to <brin the span tag, and line changed automatically.
Problem here is when I run it in Netscape and Safari, the line break
in textarea does not change to <br>, and all the text in the textares
are displayed in one paragraph.

Can anyone tell me how to display the multi-line paragraph contents
of the textarea in the <spaninnerHTM L correctly to have <br>
there?
<script type='text/javascript'>
function displayit() {
document.getEle mentById("txtVa lue").innerHTM L =
document.forms[0].tex1.value.rep lace(/\n/g,'<br>');
}
</script>

You may need to test and replace CF or LF characters too, I only
tested quickly in Firefox, IE and Opera.

This is only for NS and Safari.
And Firefox and Opera...

Maybe this is their bugs?
There is no public specification for innerHTML, so simple variances in
behaviour can't be said to be a bug. :-) All you can say is that it
behaves differently in some browsers to others and deal with it (or
don't use it).
--
Rob

Feb 7 '07 #2
xhe wrote:

Hi Xhe,
Can anyone tell me how to display the multi-line paragraph contents
of the textarea in the <spaninnerHTM L correctly to have <br>
there?
Why not simply substitute line breaks in your source text by BR tags,
right before writing your innerHTML?

<form action="#">
<textarea onkeyup="foo(th is.value)"></textarea>
<span id="txtValue"> </span>
</form>
<script type="text/javascript">
function foo(s){
document.getEle mentById("txtVa lue").innerHTML =
s.
replace(/&/g,"&amp;").
replace(/</g,"&lt;").
replace(/>/g,"&gt;").
replace(/\r\n|\r|\n/g,"<br>");
}
</script>

(untested on the targeted platform)
Regards,
Elegie.
Feb 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2573
by: Alexander Ross | last post by:
I have an html snippet, and I want to remove any <span> tags that have a specific attribute (class=none) ex. The quick brown <span class="animal">fox</span> jumped <span class="none">over</span> the lazy dog should become The quick brown <span class="animal">fox</span> jumped over the lazy dog
23
4075
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to <foo/>) From XHTML specification:
9
9223
by: red | last post by:
If I have <span>text</span> <br> and then some text isn't there sopposed to be a line break between the span and the text ? Why do browsers ignore the <br> ?
6
2830
by: hsomob1999 | last post by:
so i have a <ul> and I allow the user to append items to it. The problem is that on mozilla the <span class="line"> which is just a line to divide the sections gets overlaped and doesnt move down and adjust to the newly added items like it does in iE. It just occured to me that i dont really have to use a span, and a html <hr> tag could do the trick -I will go try. But aside from that could some one explain why this occurs? And will I get...
13
1802
by: meltedown | last post by:
Earlier, there was a discussion of why not to use <br>s too much. I mostly don't like using <br>s at all but there is one situation where its seems better than the alternative. <h4> this is the paragraph header</h4> <p> this is the paragraph</p> If I want no margin between the header and the paragraph, I can use: <h4 class='no_bottom_margin'> this is the paragraph header</h4> <p class='no_top_margin'> this is the paragraph</p>
3
4535
by: laredotornado | last post by:
Hi, Below I have an unordered list that is displayed on the same horizontal plane (thanks for the help yesterday). What I am wondering now is I would like the contents of the DIV with class "tabs- container" to be always displayed on the next line. Right now, it is being displayed on the same line as the unordered list. I could apply a <BRtag, I suppose, but I was hoping there is a more elegant, CSS way to move the content to the...
5
5802
by: Memphis Steve | last post by:
Is is possible to control spacing between two lines when using <br />? I would like to be able to adjust the spacing between the two lines in each link below so that the two lines sit snugly on top of each other within each anchor without a lot of extra space between each line. I am self taught in XHTML and CSS and would appreciate any suggestions? THE XHTML: <ul id="ns-buttons-links"> <li id="nsbl-request"><a href="#"><span...
7
3624
by: Nathan Sokalski | last post by:
Something that I recently noticed in IE6 (I don't know whether it is true for other browsers or versions of IE) is that it renders <br/and <br></br> differently. With the <br/version, which is what most people use when they write static code (some people use <br>, but with xhtml you are required to close all tags), IE6 simply breaks to the next line like it is supposed to. However, with <br></br>, which is what is sometimes generated by...
8
13148
luke14free
by: luke14free | last post by:
Hello, I'm creating a form to let user leave comments, I'm having a problem, because I need to convert all the \n to <br/>. After several tries I came out with this simple function <script language="jscript"> function repp() { var ss = document.getElementById('text').value; ss = ss.replace(/\r\n/g,"<br />"); document.getElementById('text').value = ss; } </script>
0
8706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8944
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8899
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7786
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3075
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2364
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2016
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.