473,408 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

innerHTML in Netscape

Can anyone tell me why the following bit of code doesn't work in Netscape
(6) but does in IE6 ?
It is just an example which is supposed to toggle some text in both the
<textarea> and <p> elements but what happens in Netscape is that the
<textarea> seems to get overwritten rather than written to whereas the <p>
element is just written to or removed.

-------Problem code-----
<html>
<script language='JavaScript'>
var on = false;
function fill_text() {
if(!on) {
document.getElementById('test1').innerHTML="Testin g";
document.getElementById('test3').innerHTML="Hello" ;
on= true;
}
else {
document.getElementById('test1').innerHTML="";
document.getElementById('test3').innerHTML="";
on= false;
}
</script>
<body>
<textarea name='test1' id='test1'></textarea>
<p name='test3' id='test3'></p>
<button name='test2' id='test2' onclick='fill_text();'>Do It</button>
</body>
</html>
----End problem code------------

Thanks for any help
Martin.

Jul 20 '05 #1
2 3540
I have verified this in NN 6.1 (after putting in the missing } in fill_text()),
and I don't have an explanation for you although I can tell you from
past experience that NN is not a happy camper when modifying
innerHTML for some elements such as <BUTTON>.

if you use .value instead of .innerHTML for the textarea,
you get the expected behaviour.

Csaba Gabor from New York

"Martin Turner" <ma***********@skynet.be> wrote in message news:3f*********************@reader0.news.skynet.b e...
Can anyone tell me why the following bit of code doesn't work in Netscape
(6) but does in IE6 ?
It is just an example which is supposed to toggle some text in both the
<textarea> and <p> elements but what happens in Netscape is that the
<textarea> seems to get overwritten rather than written to whereas the <p>
element is just written to or removed.

-------Problem code-----
<html>
<script language='JavaScript'>
var on = false;
function fill_text() {
if(!on) {
document.getElementById('test1').innerHTML="Testin g";
document.getElementById('test3').innerHTML="Hello" ;
on= true;
}
else {
document.getElementById('test1').innerHTML="";
document.getElementById('test3').innerHTML="";
on= false;
}
</script>
<body>
<textarea name='test1' id='test1'></textarea>
<p name='test3' id='test3'></p>
<button name='test2' id='test2' onclick='fill_text();'>Do It</button>
</body>
</html>
----End problem code------------

Thanks for any help
Martin.

Jul 20 '05 #2
"Martin Turner" <ma***********@skynet.be> writes:
Can anyone tell me why the following bit of code doesn't work in Netscape
(6) but does in IE6 ?
Netscape 6 is a badly broken piece of beta software, and should be
upgraded ASAP. However, the problem occurs in later Mozillas too.
It is just an example which is supposed to toggle some text in both the
<textarea> and <p> elements but what happens in Netscape is that the
<textarea> seems to get overwritten rather than written to whereas the <p>
element is just written to or removed.
In Mozilla Firebird 0.6, the same problem occurs. The most probable
reason is that using innerHTML on a textarea isn't the best way of
writing to it. The contents of a textarea *isn't* HTML, it is plain
text (so inner*HTML* isn't appropriate), and to change it, you use the
value property.
document.getElementById('test1').innerHTML="Testin g";
Try:
document.getElementById('test1').value = "Testing";

If you check it, using "innerHTML" actually inserts a text node as a
child of the textarea. The contents of that node is visible through
the textarea. Try pressing "Do It", and then change the contents of the
textarea manually.
on= false;
}


Missing a "}" here in the example.

Short summary: don't use innerHTML on elements that cannot contain
HTML.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3

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

Similar topics

5
by: Soren Vejrum | last post by:
I am working on a web-based html editor using MSIE's designmode and iframes. Everything works just fine, but MSIE changes all my relative "a href" and "img src" links (i.e. "/index.asp") to...
2
by: nick | last post by:
Hi All. I have a document loaded into browser. Later, I am loading some HTML content (using hidden frame) and replace some part of my document with new content, using innerHTML property. The...
4
by: Mitch | last post by:
Here is some code I have bastardised from a few places, Obviously the innerHTML coding won't work in Mozilla, could anyone suggest a work around or fix? cheers, Mitch....
4
by: Reed | last post by:
I'm having a problem with apostrophes & quotes when using body.innerHTML. With the statement: bodyText = document.body.innerHTML If there was a Form object on my page such as: <input...
7
by: KK | last post by:
Please help! I am currently experiencing a bug in Safari v125.9. When I modify the value of form input box and then get the innerHTML property of the surrounding div object - I am returned the...
8
by: Clément | last post by:
Hi! I am currently developping a user interface with Ajax/C#/.net. And I am facing a problem with Mozilla, and Firefox. I use the function innerHTML to load a Web UserControl into a div, this...
4
by: tcole6 | last post by:
My problem appears to be Firefox specific. I have a hyperlink that loads a new window. This window contains hyperlinks that call javascript functions in the parent window and then closes the...
2
by: xhe | last post by:
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='displayit();'></textarea>...
2
by: charlesjylee | last post by:
I am working with Netscape 7.0 and need to bind a <divwith the innerHTML property. More specifically, I need to bind a GridView in the div in question. I am binding the div with some hardcoded...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...

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.