I'd consider dropping the document.layers bit unless you have enough
Netscape 4 visitors to justify it.
>
> 1. Is there anyway to default this to HIDE ?

Use the above function and in the body tag:

<body onload="showHide('myId');">

That way users without JavaScript will not have the element hidden
(without JS they'll never be able to reveal it).
> 2. How would I change the button, to a checkbox or image ?

First, you don't need a form around your button if the button is just
there by itself.

Second, you can use any element that has an onclick attribute (or any
other intrinsic event you choose to use) defined in the HTML spec (which
is most of them). But if you use a checkbox, should the element be
hidden when its selected or shown?

And now users with JS disabled or not available will never see the
content - I guess they could look at the source. :-x

This issue is normally solved by making your page function properly
without any scripting at all, then add script to enhance the 'user
experience'. It is not good to have non-functioning checkboxes and
buttons, so often other UI elements are used.

The example below demonstrates some of this, it runs an onload function
to add the onclick and hide stuff. If the page is big and heavy, the
initialisation script could be added after the last 'container' div so
it runs before the page has fully loaded. Otherwise users may see all
the content displayed, then see it disappear when the onload runs.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!