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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

visibility of <select> after loop 1

Status
Not open for further replies.

nickdel

Programmer
May 11, 2006
367
GB
This is a bit of strange one although it's probably my fault!

I loop through all the <select> elements on my page and set the visibility to 'hidden'
Code:
function HideAllObj(){
var objType = document.getElementsByTagName('select');
	for(var i=0; i <= objType.length-1; i++){
		document.getElementById(objType[i].id).style.visibility = 'hidden';		
	}
}

I can run a similar function and make all these visible again however it wont let me specify a single element to make visible.
Code:
function ShowOneObj(){
	document.getElementById('MyObject').style.visibility='visible';
	}

Any idea's?

where would we be without rhetorical questions...
 
This would be more flexible:
Code:
function ShowOneObj(objID){
    document.getElementById(objID).style.visibility = 'visible';
    }

Lee
 
Yeh the code was more for illustration purposes. Doesn't really resolve the issue though. If I hide the element with an absolute reference I can happily make visible/hidden over and over. It only happens if I hide these using a loop.

Very bizarre

where would we be without rhetorical questions...
 
You're going to have to show more code or something. There is nothing wrong with the code you've pasted. If we break the problem down to it's core elements you'll see that what you're doing works fine:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">

function show() {
   document.getElementById("s").style.visibility = "visible";
}

</script>
<style type="text/css"></style>
</head>
<body>

<select id="s" style="visibility:hidden">
   <option>1</option>
   <option>2</option>
</select>

<input type="button" value="show dropdown" onclick="show()" />

</body>
</html>

On a side note, why are you hiding all the select elements on the page anyway? I can only guess it's because you're doing some sort of div popup on the screen and in IE6 and below they are showing through the popup, right?

You might want to look into the iframe shim trick so that you don't have to mess with hiding the select controls. The iframe shim trick is nicer anyway, because you don't have the issue of <select> boxes disappearing on the page in spots where the popup isn't covering.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Another example of how fake code gets fake answers, and why you need real code to get real answers.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top