Click to See Complete Forum and Search --> : Using problem with <div> tag in Netscape
VBSpike
Oct 14th, 2001, 03:07 AM
On my web page I need to change the text of certain paragraphs depending on the information entered by the user. I wrote a code using the <div> tag (gave it ID and formatted it the way I needed it) and then I started to write JavaScript code. After I finished coding I started testing. First IE - works perfectely. Then Netscape - nothing happens. And here is the problem - why doesn't anything happen in NS if it works perfectly in IE? I assume that it is one of these stupid things that work in one browser but not in the other due to differences in the implementation (duh!!). But anyway how can I do <div> style thing in Netscape?
Here is a sample code of what I did
<html>
<script language = "JavaScript">
function sayHi(){
test.innerText = "Hello VB-World";
}
</script>
<div id="test" style: blah blah blah blah you got the idea>text</div>
</html>
Thnx for any help
Spike
VBSpike
Oct 14th, 2001, 03:27 PM
Yeah, I know that, but can you give me a sample code on how to use them. I try to copy something from the book I have and it just doesn't work in NS 6
sail3005
Oct 14th, 2001, 06:38 PM
NS6 doesn't use layers, it uses divs. just like IE.
try using document.test.innerText=somehting;
sail3005
Oct 14th, 2001, 06:59 PM
yeah, thats probably faster
QWERTY
Oct 15th, 2001, 02:23 AM
actually to make it work you'd have to write something like this:
<html>
<script langauge=javascript>
function sayHI() {
\\IE 4.0+ Code:
if (document.all) {
test.innerHTML = "Hello VB-World";
}else if (document.getElementById) {
\\code for NS 6+
document.geteElementById["test"].innerHTML = "Hello VB-World";
}else if (document.layers) {
\\code for NS 4+
document.test.document.write("Hello VB-World");
}
}
</script>
<div id="test"></dic>
</html>
To be honest the last part for Netscape 4+ doesn't want to work (gives you an error document.test has no properties), but I'm sure that you can figure something out (I didn't but most of the visitors I get have very updated borwsers so I don't care about NS4).
But anyway the above should work just fine
Marek
da_silvy
Oct 15th, 2001, 03:04 AM
That doesn't look like div tags, whoever said that...?
QWERTY
Oct 15th, 2001, 10:55 AM
what do you mean? Of course it is div tags. That's the only way you'll make it work in Netscape. Only change this line:
document.geteElementById["test"].innerHTML = "Hello VB-World";
to
document.geteElementById( "test") .innerHTML = "Hello VB-World";
and it will work the way it should
Marek
P.S. Earl of Gonds' code won't work in NS6
CiberTHuG
Oct 15th, 2001, 11:33 AM
Yes, well, getElementById (with one less e), but yes, that will work.
I tend to instantiate a JavaScript var to hold the address returned by getElement and the call the methods on it. But six half dozen of one.... :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.