DHTML in Netscape

W

WJ

I have some DHTML that is showing and hiding a div. This works in IE and
Firefox, but not in Netscape.

<html>
<head>
<script language="javascript">
function switchDisplay()
{
if (myDiv.style.display=='block')
myDiv.style.display='none';
else
myDiv.style.display='block';
}
</script>
</head>
<body>
<form myform. . . >
<myDiv style="display:block">
blah
</myDiv>
<input type="button" value="test me" onclick="javascript:
switchDisplay();">
</form>


</body>
</html>

In the javascript, I can refer to the div directly in IE and Firefox (and
Mozilla). It does nothing in Netscape.

I've tried document.myDiv.style.display,
document.elements['myDiv'].style.display, and trying to walk the DOM through
the form.

Any suggestions would be greatly appreciated.

Thx!
 
D

David Dorward

WJ said:
I have some DHTML that is showing and hiding a div. This works in IE and
Firefox, but not in Netscape.

Netscape what? 3 or less? 4.x? or 6 and above?

3 doesn't do "DHTML".
4 is a buggy nightmare with dwindling market hare and not worth worrying
about.
6 should support pretty much anything any other Gecko based browser
supports.
<html>
<head>
<script language="javascript">

The Language attribute is deprecated, and the type attribute is required.
function switchDisplay()
{
if (myDiv.style.display=='block')

What is "myDiv"? You need to use document.getElementById (or document.all
for ancient versions of IE, or goodness knows what for Netscape 4) to get
an object reference first.
<myDiv style="display:block">

There is no "myDiv" element in HTML.
<input type="button" value="test me" onclick="javascript:
switchDisplay();">

Loose the "javascript:" bit.
 
T

Toby Inkster

WJ said:
I have some DHTML that is showing and hiding a div. This works in IE and
Firefox, but not in Netscape.

What do you mean by "Netscape"? There are significant differences between,
say, Netscape 4.08 and Netscape 7.1.
 
W

WJ

Most humble apologies. I'm trying this with Netscape 7.2 The Div is
<div name="myDiv" id="myDiv" style="display:block">

.. . .

</div>
 
T

Toby Inkster

WJ said:
function switchDisplay()
{
if (myDiv.style.display=='block')
myDiv.style.display='none';
else
myDiv.style.display='block';
}

Function should read:

function switchDisplay() {
myDiv = document.getElementById('myDiv');
if (myDiv.style.display=='block') myDiv.style.display='none';
else myDiv.style.display='block';
}
<div name="myDiv" id="myDiv" style="display:block">
. . .
</div>

HTML should read:

<div id="myDiv">...</div>

The other attributes style/name are not needed.
 
D

DU

WJ said:
Most humble apologies. I'm trying this with Netscape 7.2 The Div is
<div name="myDiv" id="myDiv" style="display:block">

. . .

</div>

There is no name attribute for div elements. Also, I recommend to never
use the same identifier for name and id attributes.
As mentioned by others, style="display:block" is also pointless as this
is the default display declaration in all CSS-capable browsers.

DU
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top