473,802 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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='JavaS cript'>
var on = false;
function fill_text() {
if(!on) {
document.getEle mentById('test1 ').innerHTML="T esting";
document.getEle mentById('test3 ').innerHTML="H ello";
on= true;
}
else {
document.getEle mentById('test1 ').innerHTML="" ;
document.getEle mentById('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_t ext();'>Do It</button>
</body>
</html>
----End problem code------------

Thanks for any help
Martin.

Jul 20 '05 #1
2 3555
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******** *************@r eader0.news.sky net.be...
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='JavaS cript'>
var on = false;
function fill_text() {
if(!on) {
document.getEle mentById('test1 ').innerHTML="T esting";
document.getEle mentById('test3 ').innerHTML="H ello";
on= true;
}
else {
document.getEle mentById('test1 ').innerHTML="" ;
document.getEle mentById('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_t ext();'>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.getEle mentById('test1 ').innerHTML="T esting";
Try:
document.getEle mentById('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
21634
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 absolute links (i.e. "http://localhost/index.asp") when I set the iframe's innerHTML. This is bad as the links are supposed to be relative. How can I avoid this? Any solutions/suggestions are much appreciated.
2
2140
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 question is - how can I get notified when my document is changed ? Regards, Nick
4
5025
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. ****************snip************************* <html> <head> <title>Untitled</title>
4
3066
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 name="email" type="text" id="email"> bodyText transilates it into <input name=email type=text id=email>
7
3475
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 original form value not the changed value! Has anyone else encountered this? Cheers.
8
7775
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 way the main page never gets refreshed. It works perfectly under IE, but with Mozilla and Firefox I got a problem : there is a space before the thing I want to display everytime I use ".innerHTML".
4
5133
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 child window. The function that is called contains an XMLHttpRequest. My problem is that everything happens as it should, the innerHTML is changed by the results of the XMLHttpRequest and the child window closes. The problem is this, in Firefox,...
2
19590
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> </form> <span id="txtValue"></span> <script language='javascript'>
2
2553
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 data (a table, which is the HTML equivalent of a GridView). Is there a way with javascript to dump the memory used by a DOM object (the div that I am binding with innerHTML)? When i just receive the variable in javascript, it doesnt seem to leak....
0
9562
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10305
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
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
10063
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...
1
7598
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
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
4270
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
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
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.