SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple property for listbox?

    Is there a multiple property that I can set for a listbox?


    I have a listbox that is set for only single selections, but I'd like to be able to set it to multiple within a JavaScript function. Is this possible?

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2005
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to create your box like this:

    PHP Code:
    <SELECT name="MyBox" MULTIPLE size="10"

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes. Is there a way to set that property through Javascript code?

  4. #4
    SitePoint Zealot
    Join Date
    Aug 2005
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could create a DIV and use innerHTML.

    Why going thru all that trouble when you can set it to multiple from the beginning?

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try working with the Javascript Select object; note the type property. ('select-one' or 'select-multiple')

  6. #6
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The type property is read-only, whereas the multiple property is read-write. Setting the multiple property of the select object to 'multiple' will have the same effect as adding the attribute multiple="multiple" in the select tag (note: multiple="multiple" is the sanctioned syntax for this attribute).

    Be aware that messing with this property will flat-out crash some browsers.

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JVLB
    The type property is read-only, whereas the multiple property is read-write. Setting the multiple property of the select object to 'multiple' will have the same effect as adding the attribute multiple="multiple" in the select tag (note: multiple="multiple" is the sanctioned syntax for this attribute).

    Be aware that messing with this property will flat-out crash some browsers.

    Thanks, that's what I was looking for. I was able to use:

    this.form['lstbxChangeMenuItemOrder'].multiple = true;
    this.form['lstbxChangeMenuItemOrder'].multiple = false;


    It works fine in Firefox 1.5. It didn't work in IE 6, but it didn't crash it.

  8. #8
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you use the syntax I suggested, it will work in IE as well. It will crash at least some versions of Konqueror and Safari. It does not appear to do anything in Opera.

    A potential work-around that would likely provide more universal functionality would be to create two identical selects in the markup, one with multiple and one without and toggle their display values between none and inline.
    Last edited by JVLB; Jul 16, 2006 at 09:49.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •