hide <label>

X

Xerxes

Hi,
can you tell me how I can make a <label> hidden?
I have hidden the field after the label:

var M_Hide = isNS4?'hide':'hidden';
var M_Show = isNS4?'show':'visible';
.....
<label id="uid">UserID: </label>
<input name="UserID" type="text" value="" size="20">
<script language="Javascript1.2" type="text/javascript1.2">
var input = document.theForm.UserID;
if (input.style)
input.style.visibility=M_Hide;
</script>

but I am not sure how to hide: <label id="uid">UserID: </label> since
<label> does not have a "name" field.

Thanks.
 
M

Martin Honnen

Xerxes said:
Hi,
can you tell me how I can make a <label> hidden?
I have hidden the field after the label:

var M_Hide = isNS4?'hide':'hidden';
var M_Show = isNS4?'show':'visible';
....
<label id="uid">UserID: </label>
<input name="UserID" type="text" value="" size="20">
<script language="Javascript1.2" type="text/javascript1.2">
var input = document.theForm.UserID;
if (input.style)
input.style.visibility=M_Hide;
</script>

but I am not sure how to hide: <label id="uid">UserID: </label> since
<label> does not have a "name" field.

You should make the label contain the input
<label id="uid">...<input ...></label>
to associate the <label> with the <input>, then use
var label;
if (document.all)
label = document.all.uid;
else if (document.getElementById)
label = document.getElementById('uid');
if (label && label.style)
label.style.visibility = 'hidden';
Depending on what you want to achieve you might prefer
label.style.display = 'none'
which hides the <label> and frees the screen spays it occupied (content
is reflown)
 
X

Xerxes

Hi,
thanks for the info. This is not quite working the way I want. I should
have elaborated a bit more.
I am trying to make an input field, and its label, visible or hidden
depending on what radio button is clicked.
The input field represents IP address and the radio buttons are DHCP and
Static IP. If the user clicks on the Static IP button, I want the IP
address input field become visible and if the user clicks on DHCP, I
want the field, and its label, to disappear.

What I had was this (couldn't make label disappear:)

<tr>
<td><h3>Addressing</h3>
</td>
<td><h4>DHCP <input name="NetAddressing" type="radio" value="DHCP"
checked
onClick="if (this.checked)
{
if (this.form['Static IP Address'].style){
this.form['Static IP
Address'].style.visibility=M_Hide;
}
}
else if (this.form['StaticIPAddress'].style){
this.form['Static IP Address'].style.visibility =
M_Show;
}">
</h4>
</td>
<td><h4>Static IP
<input name="NetAddressing" type="radio" value="Static IP"
onClick="if (this.checked)
{
if (this.form['Static IP Address'].style){
this.form['Static IP
Address'].style.visibility=M_Show;
this.form['Static IP Address'].focus();
}
}
else if (this.form['Static IP Address'].style){
this.form['Static IP Address'].style.visibility =
M_Hide;
}">
</h4>
</td>
<td><h4><label>IP Address: </label></h4>
<td>
<input name="Static IP Address" type="text" value="0.0.0.0"
size="20">
<script language="Javascript1.2"
type="text/javascript1.2">
var input = document.netForm['Static IP
Address'];
if (input.style)
input.style.visibility=M_Hide;
</script>
</td>
</tr>

where:

var isIE4 = document.all;
var isNS4 = document.layers;
var isNS6 = document.getElementById && !document.all;

var M_Hide = isNS4?'hide':'hidden';
var M_Show = isNS4?'show':'visible';

Thanks.
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top