Connecting Tech Pros Worldwide Forums | Help | Site Map

How to change WIDTH of empty SELECT box with no dynamic elements added

JJA
Guest
 
Posts: n/a
#1: Jul 23 '05
I would like to know how to expand the width of SELECT boxes with
Javascript. These have the MULTIPLE attribute and a SIZE attribute
greater than 1 (usually around 10 or so).

The OPTION elements are dynamically constructed from database content.

I've observed that the overall width of the SELECT element seems to be
equal to the width of the entry with the most text.

How can set the width with Javascript?

When I have no entries, the box looks strangely narrow.

Thomas Hoheneder
Guest
 
Posts: n/a
#2: Jul 23 '05

re: How to change WIDTH of empty SELECT box with no dynamic elements added



"JJA" <johna@cbmiweb.com> schrieb im Newsbeitrag
news:2cfb40c2.0410131050.10777d@posting.google.com ...[color=blue]
> How can set the width with Javascript?[/color]

Assuming that you have a form with name="myform" and a sellect with
name=myselect", you can do this with document.myform.myselect.style.width,
e. g. you could ask:
if (document.myform.myselect.length == 0)
document.myform.myselect.style.width = "100px";

Hope this helps you.

Nice greetings from
Thomas


Ivo
Guest
 
Posts: n/a
#3: Jul 23 '05

re: How to change WIDTH of empty SELECT box with no dynamic elements added


"JJA" wrote[color=blue]
> I would like to know how to expand the width of SELECT boxes with
> Javascript. These have the MULTIPLE attribute and a SIZE attribute
> greater than 1 (usually around 10 or so).[/color]

Strange. In my observation 4 to 6 seems to be the most favourite size.
[color=blue]
> I've observed that the overall width of the SELECT element seems to be
> equal to the width of the entry with the most text.
> How can set the width with Javascript?[/color]

You create a reference to the select element, by means of its name or
document.getElementsByTagName('select')[index_number] and then set the width
attribute of its style object. For example:

myselectreference.style.width='10em';

In CSS it is even easier, and it even works with javascript off:

<select style="width:10em;"></select>
[color=blue]
> When I have no entries, the box looks strangely narrow.[/color]

Then there should no select element at all, I would think, but instead a
message explaining its absence.
--
Ivo


Closed Thread