Forum Moderators: open

Message Too Old, No Replies

Netscape + DHTML + document.all

I am using document.all.... .style.display. Not working in Netscape

         

Oegma

12:08 pm on Mar 5, 2002 (gmt 0)



Hi everybody,

I am using the following code to hide & show objects in IE5, but it's not working in Netscape?

<script language="JavaScript1.2">

function ShowMe( )
{
document.all.t3.style.display="";
}

</script>

<html>
<body>

<FORM name="x">
<input type="button" value="show" onClick="ShowMe( );">

<TABLE id="t3" style="display:none">
<TR><TD>
<FONT size="-1">Welcome to IE & NetSc problems ;-)</FONT>
</TD></TR>
</TABLE>

</FORM>

</body>
</html>

Any help will be welcome.
Thanks

BlobFisk

2:05 pm on Mar 5, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Oegma,,

Your code is fine for the IE DOM (document object model), however, Netscape has a slightly different one.

Unfortunately, document.all is not a valid Netscape object.

To access a form element in Netscape you would use the format of document.formname.elementname.

HTH

Purple Martin

12:49 am on Mar 6, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could use document.getElementById instead of document.all, which should work in IE5+ and N6+.

eg.
document.getElementById("t3").style.display = ""

Oegma

6:27 am on Mar 6, 2002 (gmt 0)



Hi BlobFisk and Purple_Martin. Thanks for the info, but the problem is that our company wants me to write code that will work on IE4 and NS4, which is not that easy. I've found some info on how to detect the browser using
if ( document.all )
.... IE4
if ( document.layers
.... NS4
so from there I can then go and do the hiding or showing of the buttons, input and form data. But the problem I've got know is I am using <DIV> tags to put the info that I want to hide/show in it. It once again works fine for IE, but not for NS4 ;-( Here's the code that I am working on now. If this works, we can use only one function to do both IE & NS hide/show stuff. Have a look, and tell me what I am doing wrong here:

<script language="javascript">
function show(id)
{
if (ns4)
document.layers[id].visibility = "show"
else if (ie4)
document.all[id].style.visibility = "visible"
}

function hide(id)
{
if (ns4)
document.layers[id].visibility = "hide"
else if (ie4)
document.all[id].style.visibility = "hidden"
}

function go( )
{
ns4 = (document.layers)? true:false;
ie4 = (document.all)? true:false;

alert( "Nescape : "+ns4 );
alert( "IE : "+ie4 );
hide( 'd1' );
}

function Show_NOW( )
{
show( 'd1' );
}

function Hide_NOW( )
{
hide( 'd1' );
}

</script>

<html>
<body onLoad="go( );">

<div id="d1">
<table>
<tr>
<td>
BLOCK A
</td></tr>

<tr>
<td>
<div id="d2">
<table>
<tr>
<td>
BLOCK B
</td></tr>
</table>
</div>
</td></tr>

</table>
</div>

<form>
<input type="button" name="x" value="SHOW" onClick="Show_NOW( );">
<input type="button" name="z" value="HIDE" onClick="Hide_NOW( );">
</form>

</body>
</html>