Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using display:none for labels

0 views
Skip to first unread message

Nathan Sokalski

unread,
Jul 24, 2006, 8:04:07 PM7/24/06
to
I have 4 elements that I want to hide, which are coded as follows:


<label for="ddlGradientMode" id="lblGradientMode"
name="lblGradientMode">GradientMode: </label>
<select name="ddlGradientMode" id="ddlGradientMode"></select>
<label for="txtTexture" id="lblTexture" name="lblTexture">Texture: </label>
<input name="txtTexture" type="text" id="txtTexture" style="width:400px;" />


I use the following JavaScript to attempt to hide them:


document.forms[0].lblGradientMode.style.display='none';
document.forms[0].ddlGradientMode.style.display='none';
document.forms[0].lblTexture.style.display='none';
document.forms[0].txtTexture.style.display='none';


However, this code does not seem to work for the label tags. Why is this,
and how can I fix it? Thanks. (NOTE: I am using IE6 on Windows XP Pro)
--
Nathan Sokalski
njsok...@hotmail.com
http://www.nathansokalski.com/


dNagel

unread,
Jul 24, 2006, 8:19:02 PM7/24/06
to Nathan Sokalski


A guess might be that they are not members of the form since they can not hold user data.

D.

Nathan Sokalski

unread,
Jul 24, 2006, 8:42:30 PM7/24/06
to
They might not be able to hold user data, but they are inside the form tags.
I also tried using

document.lblGradientMode.style.display='none';

but it still did not work. Any other ideas?

"dNagel" <NOTGra...@NotMail.com> wrote in message
news:44C56376...@NotMail.com...

Walter Zackery

unread,
Jul 24, 2006, 9:31:51 PM7/24/06
to

"Nathan Sokalski" <njsok...@hotmail.com> wrote in message
news:OSPrzM4r...@TK2MSFTNGP03.phx.gbl...
: They might not be able to hold user data, but they are inside the form
tags.
: I also tried using
:
: document.lblGradientMode.style.display='none';
:
: but it still did not work. Any other ideas?
: --
: Nathan Sokalski
: njsok...@hotmail.com
: http://www.nathansokalski.com/

lblGradientMode.style.display='none';
or
document.all.lblGradientMode.style.display='none';
or
document.forms[0].all.lblGradientMode.style.display='none';
or (cross-browser)
document.getElementById('lblGradientMode').style.display='none';

:
: "dNagel" <NOTGra...@NotMail.com> wrote in message

:
:


Nathan Sokalski

unread,
Jul 24, 2006, 10:25:40 PM7/24/06
to
I tried every one of those, and none of them worked. They all caused the
browser to give an error say it is null or not an object.

"Walter Zackery" <please_r...@group.com> wrote in message
news:O8wRbo4r...@TK2MSFTNGP03.phx.gbl...

Dave Anderson

unread,
Jul 25, 2006, 3:12:21 PM7/25/06
to
Nathan Sokalski wrote:
> <label for="ddlGradientMode" id="lblGradientMode"
> name="lblGradientMode">GradientMode: </label>
>
> document.forms[0].lblGradientMode.style.display='none';

This...
document.forms[0].lblGradientMode

...is shorthand notation for:
document.forms[0].elements["lblGradientMode"]

As such, the element must be of the appropriate type for the collection:
http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/html.html#ID-76728479

In this case, that is a control. LABEL is not listed among the control types
in HTML:
http://www.w3.org/TR/html401/interact/forms.html#didx-control

This should not worry you, since you can use document.getElementById(). I
know you can use it because you use the ID attribute, which requires
uniqueness. Therefore, the following will suffice:

document.getElementById("lblGradientMode").style.display = "none"

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.


Mike Jansen

unread,
Aug 10, 2006, 10:01:14 AM8/10/06
to
Some thoughts...

Do you have a style for label that defines the display, e.g. <style...>label
{ display:block; }</style>. I seem to remember having a problem using
JavaScript to override a style that was defined in a stylesheet or <style>
tag. Can't remember what the exact issue was.

Have you written some test JavaScript that just tries to access the label
and do something else besides change the style? Narrow down your issue.
Maybe you're just not getting a handle on the object.

Have you tried it on different browsers? Perhaps you are running into the
joys of browser incompatibilities/non-standardization.


Mike

"Nathan Sokalski" <njsok...@hotmail.com> wrote in message

news:u4H4W33r...@TK2MSFTNGP04.phx.gbl...

0 new messages