Select dropdown

Discussion in 'Javascript' started by Wolfgang, Dec 14, 2006.

  1. Wolfgang

    Wolfgang Guest

    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
     
    Wolfgang, Dec 14, 2006
    #1
    1. Advertising

  2. Wolfgang

    Erwin Moller Guest

    Wolfgang wrote:

    > 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 ?


    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

    >
    > Thanks
    > Wolfgang
     
    Erwin Moller, Dec 14, 2006
    #2
    1. Advertising

  3. Wolfgang

    ASM Guest

    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;
    }




    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
     
    ASM, Dec 14, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vishnu
    Replies:
    1
    Views:
    1,242
    Patrick.O.Ige
    Mar 25, 2006
  2. Mike
    Replies:
    1
    Views:
    844
  3. acadam
    Replies:
    0
    Views:
    779
    acadam
    Dec 27, 2006
  4. Replies:
    2
    Views:
    458
  5. palmiere
    Replies:
    1
    Views:
    453
    Erwin Moller
    Feb 9, 2004
Loading...

Share This Page