Results 1 to 4 of 4

Thread: HTML select list non selectable

  1. #1
    Join Date
    Jul 2008
    Posts
    65
    Thanks
    42
    Thanked 0 Times in 0 Posts

    Default HTML select list non selectable

    Is there a way I can have an option in a SELECT list be non selectable?
    I have a
    Code:
    <option>----------------------</option>
    For a break between to options. But I want it so when they drop down the SELECT list and they put there mouse over the break option it does not highlight. Thanks

  2. #2
    Join Date
    Sep 2008
    Location
    Whiteford, MD
    Posts
    39
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default

    You can use javascript and disable it I believe...but that would be redundant, yes?

  3. #3
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Use the disabled attribute.

    http://www.w3schools.com/TAGS/tag_option.asp

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I don't think so. In FF it's easy:

    Code:
    <option disabled>----------------------</option>
    But IE 7, probably others will not go along with that. There are various things you can do to it in javascript, like return false or blur it onclick, onselectstart, onmouseover or onfocus, but none of these seem to work in IE 7 either. The select can have its onchange event, but I can't see any way of using that either, it fires after the option is selected - it still won't prevent the option from being selected, it could discard it in favor of another option, but the select will still close, and the option will still be available in the drop down list.

    I think that the only cross browser solution that might work would be to use a substitute select element made up of divisions, each with their own javascript events attached to them.

    However, something like so might be acceptable:

    Code:
    <select name="" onchange="if (this.options.selectedIndex == 4){this.options.selectedIndex = 0;alert('Please select an option.');this.focus();}">
    <option value="" selected>Select</option>
    <option value="">a1</option>
    <option value="">b1</option>
    <option value="">c1</option>
    <option value="" disabled>---------------------</option>
    <option value="">a2</option>
    <option value="">b2</option>
    <option value="">c2</option>
    </select>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •