Select dropdown

W

Wolfgang

Hi,
is there a possibility to change the size of the select-dropdown-box ?
I predefine the length of the option-area with 10 inside HTML as
follows:

<select class="select250" name="projectTypeSelect">
<script language="JavaScript"
type="text/javascript">document.lopForm.projectTypeSelect.options.length=10;</script>
</select>

The resulting dropdown-box will be 10 rows long.

If I have less entries, let's say 4, there will be 6 empty rows and I
want to shorten
the dopdownbox to 4 rows.

Anyone knowing a way to do this ?

Thanks
Wolfgang
 
E

Erwin Moller

Wolfgang said:
Hi,
is there a possibility to change the size of the select-dropdown-box ?
I predefine the length of the option-area with 10 inside HTML as
follows:

<select class="select250" name="projectTypeSelect">
<script language="JavaScript"
type="text/javascript">document.lopForm.projectTypeSelect.options.length=10; said:
</select>

The resulting dropdown-box will be 10 rows long.

If I have less entries, let's say 4, there will be 6 empty rows and I
want to shorten
the dopdownbox to 4 rows.

Anyone knowing a way to do this ?

Hi,

You can simply find all individual options inside a SELECT via:
document.formname.selectname.options.
It will return an array with Option objects in them.
on each Option you can get the text and value.

In your case you can remove the options that contain no text or no value.
You can remove an option by setting the value to null (in the array that
contains the options).

But I wonder why you add 10 options in the first place...
Why not just add what you need?

Regards,
Erwin Moller
 
A

ASM

Wolfgang a écrit :
Hi,
is there a possibility to change the size of the select-dropdown-box ?
I predefine the length of the option-area with 10 inside HTML as
follows:

why not to have a dropdown of 0 option (length = 0)
and increase it step by step ?


var S = document.lopForm.projectTypeSelect.options;
S.length = 0;
for(var i=0; i<4; i++)
{
var o = new Option('text '+i, 'val '+i);
S[S.length] = o;
}
 

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,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top