Resize select listbox

GreGorGy

BULLSFAN
Joined
Jan 18, 2005
Messages
15,290
Reaction score
1,527
Location
Benoniebfkweesnie
Actually, I thought this would be easy. Alas!

I have the following HTML:
Code:
....
<STYLE TYPE="text/css" TITLE="text/css">
	select.selectClass
		{
		width: 140px;
		border: 1px solid gray;
		height: 200px;
		}
</STYLE>

....

<SELECT NAME="mySelect" ID="mySelect" CLASS="selectClass" SIZE=5>
	<OPTION>One
	<OPTION>Two
	<OPTION>Three
	<OPTION>Four
	<OPTION>Five
	<OPTION>Ten
	<OPTION>Twenty
</SELECT>

....
<SCRIPT TYPE="text/javascript" LANGUAGE=JAVASCRIPT CHARSET=UTF-8>
	document.getElementByID("mySelect").style.height = 20;
</SCRIPT>
....

No way in hell will the SELECT listbox change its height. Does anyone know if this can be done?
 
(CSS) Styles need to be assigned a measurement unit - ie. 20px, or 20pt, or 20em, etc. That might make all the difference. (Only 0 is unit-free)

Code:
<script type="text/javascript">
	document.getElementByID("mySelect").style.height = 20px;
</script>
 
(CSS) Styles need to be assigned a measurement unit - ie. 20px, or 20pt, or 20em, etc. That might make all the difference. (Only 0 is unit-free)

Code:
<script type="text/javascript">
	document.getElementByID("mySelect").style.height = 20px;
</script>

Nope - no difference.

Style and JS - when JS alone was not working, I figured it wouldn't kill to set a value in CSS first. And yes, proof of concept for what has to become dynamic later.
 
OK, it can be half-done using some hard thinking and mathematics and some rules and changes to the code:

(1) No height in your CSS - rather do the maths and figure out how many lines that height will produce.
Code:
select.selectClass
		{
		width: 140px;
		border: 1px solid gray;
		/* height: 200px; -- remove this */
		}


(2) Use that lines calculation as your size attribute in your SELECT:

Code:
<SELECT NAME="mySelect" ID="mySelect" CLASS="selectClass" SIZE=13>

Now, take note that we are no longer pixel accurate but least if we need a SELECT to fill a screen (iFrame in my case) as I did, this is as close as it comes

(3) The javascript changes slightly:
Code:
document.getElementByID("mySelect").size = 3;

size can go up or down. This is the only method I have found which works. Know of any others?
 
Top
Sign up to the MyBroadband newsletter
X