By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,572 Members | 946 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,572 IT Pros & Developers. It's quick & easy.

hide <label>

P: n/a
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.
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a


Xerxes wrote:
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)
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

P: n/a
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.

"Martin Honnen" <Ma***********@t-online.de> wrote in message
news:3F**************@t-online.de...


Xerxes wrote:
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)
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.