Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding a HTML label with Javascript

Status
Not open for further replies.

golyg

Programmer
Jul 22, 2002
319
US
I am calling a javascript function and in there I am checking to see the value of a listbox and if its a particular value I would like to show a label...but I keep getting this error:
"'hisForm.other' is null or not an object"

So, how do I hide the HTML label in Javascript?


thanks
 

You can either refer to it by name:

Code:
document.forms['formname'].labelName.style.visibility = 'hidden';

Or by ID:

Code:
document.getElementById('labelId').style.visibility = 'hidden';

Hope this helps,

Dan
 
I'm getting an "object required" error....
I'm using the 2nd example.


thanks for your help.


 
Golyg - post a (cut-down and working) code example before, and after implementing option 2. I can only imagine that a syntax error or naming issue is causing this.

Jeff
 
Here is the dropdown that will call the onchange function:
Code:
<select name="lsClosureTypes" id="lsClosureTypes" size="1" onchange="closureType_change()">


Here is the function that is being called by onchange:
<script LANGUAGE="javascript">

function closureType_change(){
var i;
i = thisForm.lsClosureTypes.options[thisForm.lsClosureTypes.selectedIndex].value;
alert(i);
if (i == "OTHER_DISCIPLINE")
{
alert("OTHER");
document.getElementById("otherDisciplinesLabel").style.visibility = "hidden";
}
}
</script>


Thanks for your help...


 
The following HTML page works perfectly fine for me. I think you were missing the name="" in your <form> tag. Just a guess.

Code:
<html>
<head>
<script language="javascript">
function closureType_change()
{
  var i;
  i = thisForm.lsClosureTypes.options[thisForm.lsClosureTypes.selectedIndex].value;
  if (i == "OTHER_DISCIPLINE")
  {
    document.getElementById("otherDisciplinesLabel").style.visibility = "visible";
  }
}
</script>
</head>
<body>
<form name="thisForm">
<select name="lsClosureTypes" id="lsClosureTypes" size="1" onchange="closureType_change()">
<option value="0">0</option>
<option value="OTHER_DISCIPLINE">OTHER_DISCIPLINE</option>
<option value="2">2</option>
</select>
</form>
<div id="otherDisciplinesLabel" style="visibility:hidden;">This is the hidden label</div>
</body>
</html>

Jeff
 
No I have:
<form name="thisForm" METHOD="post">
in my code....
Its an asp page..any difference?

 
Well... if you copy/paste the full page demo I gave, does it work for you? If it works, then you need to look at what is different about *your* page!

You said you were getting an error (object required) when trying to implement one of BillyRay's code samples. If you don't get the same error on my demo page (which incorporates code from people in this thread), then the problem is not with the code that people have supplied you with... the problem is going to lie elsewhere on your page (maybe a syntax error - I don't know).

I'd honestly like to help you more... please take a look at the code sample I posted... copy/paste it and try loading it in your browser.

Jeff
 
Well, I wasn't using:
<div id="otherDisciplinesLabel" style="visibility:hidden;">This is the hidden label</div>

but rather dragging and dropping the design-time control label...?


thanks for everyones help!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top