473,511 Members | 14,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Show/Hide layer in Netscape/IE problem

Hi - I have a function which shows/hides a <div> on my page - this
appears to oinly work in IE, but I also need it to work in Netscape 7.1.

My function is in my head:

function openIt(faq) {
showIt = document.all(faq);
if (showIt.style.display == "none") {
showIt.style.display = ""
} else {
showIt.style.display = "none"
}
}

...and the onclick code is:

<a href="#" onclick="javascript:openIt('22list'); return false;">click
here to toggle</a>

<div id="22list" style="display:none">
This will show/hide when you click the above link
</div>
Could anyone help amend the function to run in both IE and Netscape?

Thanks for any help,

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
5 6019
Mark wrote:
Hi - I have a function which shows/hides a <div> on my page - this
appears to oinly work in IE, but I also need it to work in Netscape 7.1.
I didn't even need to look at the rest of the code to see what was wrong.
I'm sure a search in google groups would have found the answer, it seems to
come up several times a week around here.

<http://www.metalusions.com/backstage/articles/8/> appears to be a
reasonable explanation.
<a href="#" onclick="javascript:openIt('22list'); return false;">click
here to toggle</a>
(1) The "javascript:" in the onclickj event is redundent.
(2) href='#' is nasty. If you can't put a useful URL in there, don't use a
link
<div id="22list" style="display:none">


OK, I was wrong. I didn't guess what was wrong. Not everything at least. You
have two problems. The solution to the first is above, the other is that
ids may NOT begin with a number.

<http://validator.w3.org/>

--
David Dorward http://dorward.me.uk/
Jul 20 '05 #2
Mark hu kiteb:
Hi - I have a function which shows/hides a <div> on my page - this
appears to oinly work in IE, but I also need it to work in Netscape
7.1.

My function is in my head:

function openIt(faq) {
showIt = document.all(faq);
if (showIt.style.display == "none") {
showIt.style.display = ""


Change the above line to one of:

showIt.style.display = "inline";
showIt.style.display = "block";

And then be aware of the difference between them, and use them
appropriately.
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #3
"Mark" <an*******@devdex.com> wrote in message
news:3f*********************@news.frii.net...
<snip>
function openIt(faq) {
showIt = document.all(faq);
Netscape/Mozilla/Gecko browsers do not have a document.all collection so
the above line will produce errors and the rest of the function will not
be executed.

If the parameter - faq - contains a string that represents the unique ID
of an HTML element (as appears to be the case, with the caveat that
"22list" is not a valid ID attribute string according to the HTML 4
specification) then the W3C DOM standard document.getElementById method
could be used, possibly with a fall back to document.all to accommodate
IE 4.

Incidentally, document.all is an object so its named properties should
be accessed using square brackets instead of parenthesise. IE does its
error correcting/tolerance thing with code like this but other browsers
that do implement a document.all collection (there are quite a number
these days) may not be so tolerant.
if (showIt.style.display == "none") {
showIt.style.display = ""
} else {
showIt.style.display = "none"
}
}

..and the onclick code is:

<a href="#" onclick="javascript:openIt('22list');
return false;">click here to toggle</a>

<div id="22list" style="display:none">

<snip>

Initially setting the display property to none means that any visitors
to the page who have JavaScript disabled/unavailable will be presented
with a non-functional/useful link and never be able to view the content
of the DIV (unless they view the page source). Generally, if content is
to be hidden and revealed with scripts it would be better to have it
initially visible and hide it in the onload event so that the content
will be available to the users without JavaScript. Additionally, the
link is meaningless without scripting so it should probably be included
in the document using a script, so that without client-side scripting
the user doesn't ever get the impression that there was any dynamic
mechanism on the page, and certainly not the impression that it is
broken.

Richard.
Jul 20 '05 #4
"Fabian" <la****@hotmail.com> writes:
Mark hu kiteb:

showIt.style.display = ""


Change the above line to one of:

showIt.style.display = "inline";
showIt.style.display = "block";


That's not necessary. Setting the properties of the element's style
object corresponds to writing in the tag's style attribute. Setting
a style object property to the empty string is consistently (across
current browsers) equivalent to removing the property from the
attribute value. It will then take its default value (or whatever
value is given by global CSS rules).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
Hi - thank you for the replies - I'm not good with JavaScript though -
all I've been able to manage (after quite some time) is the code I've
shown - this was all through trial and error. Does anyone have a proper
routine which will both check for IE and Netscape, and toggle the
visibility/hidden/block (not sure which now!) between being shown and
not being shown - and not to leave a big gap if it is not shown?

Thanks again,

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #6

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

Similar topics

1
1289
by: Stephan | last post by:
I need a way to hide <div> that works in Mozilla/Netscape. My macromedia behavior does not work anymore. Also, and good ways to time the hideLayer? As in hide the layer after x seconds?? ...
10
3187
by: David | last post by:
Hi everyone, Hoping there are some .js/browser experts out there that can help with this weird problem. I have made a swap div routine and applied the events to menu buttons with a closer...
5
2161
by: Zambien | last post by:
Hi all, Here's my problem. I have tables that are using the menu/submenu idea for hiding rows. This works fine in IE (of course) and does show/hide correctly in netscape, but as soon as the...
3
14420
by: Ryh | last post by:
I have the following scritpt. It hides div layer when mouse is out of the div layer. Inside DIV I have IFRAME box. Unfortuantely it does not work in Mozilla or IE 5.5. It hides div when cursor is...
3
6369
by: Merlin | last post by:
Hi there, I am trying to create a form with an dynamic field that can be shown or hidden. As I saw for example on google it is possible with JS to show a layer and move the content underneath...
1
4150
by: pamate | last post by:
hi, I want to show hide layers. I am able to show and hide layers but i am facing problem that, cant view the cursor in Mozilla,but i can type in input text box, its overlapping the layers. ...
2
2126
by: dusk | last post by:
Hi, I have a page with lots of hidden divs which are revealed based on choices made at each 'layer'. So I've used naming convention which represents the order in which each div becomes...
1
3782
oranoos3000
by: oranoos3000 | last post by:
hi would you please help me i have a online shopping center that i show pictures of the my product in home page. in the InterExplorer pictures is shown correctly but in Firefox browser is shown...
0
7349
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,...
1
7074
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...
0
7506
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...
1
5063
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
4734
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...
0
3219
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3210
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
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 ...
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.