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

J

JJA

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.
 
T

Thomas Hoheneder

JJA said:
How can set the width with Javascript?

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
 
I

Ivo

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).

Strange. In my observation 4 to 6 seems to be the most favourite size.
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?

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:

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top