how to disable options in an option list?

Discussion in 'Javascript' started by Fluffy Convict, Dec 5, 2004.

  1. Does anybody know how to disable only certain options of an option list
    by a javascript function? With the following function you can disable a
    option list completely:

    function disableList()
    {
    var x=document.getElementById("myOptionList")
    x.disabled=true
    }

    But what if I just want to disable one option, or two - so that this
    option cannot be clicked / selected anymore?

    By the way: <optgroup label="disabledOption"> is not an option, since I
    have to disable / enable the options in real time according to users input.

    I've been stuck with this problem for days now, so any help would be
    greatly appreciated!
    Fluffy Convict, Dec 5, 2004
    #1
    1. Advertising

  2. Fluffy Convict

    Evertjan. Guest

    Fluffy Convict wrote on 05 dec 2004 in comp.lang.javascript:

    > Does anybody know how to disable only certain options of an option
    > list by a javascript function? With the following function you can
    > disable a option list completely:
    >
    > function disableList()
    > {
    > var x=document.getElementById("myOptionList")
    > x.disabled=true
    >}
    >
    > But what if I just want to disable one option, or two - so that this
    > option cannot be clicked / selected anymore?


    disabled, style.display and style.visibility do not work as expected.

    You could remove an option dynamically:


    <form name="testform">
    <select name="testselect" id="testselect">
    <option value="first">first option</option>
    <option value="second">second option</option>
    <option value="third">third option</option>
    </select>
    </form>



    <script type='text/javascript'>
    var node = document.getElementById('testselect');

    function removeOption(x){
    node.removeChild(node.options[x]);
    }

    removeOption(1)
    </script>
    Evertjan., Dec 5, 2004
    #2
    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. Cliff  Martin
    Replies:
    1
    Views:
    3,030
    Larry Smith
    Jan 31, 2007
  2. jacksu
    Replies:
    0
    Views:
    507
    jacksu
    Oct 9, 2007
  3. Fluffy Convict

    Disabling options in option list only works in IE

    Fluffy Convict, Dec 6, 2004, in forum: Javascript
    Replies:
    2
    Views:
    106
    Michael Winter
    Dec 7, 2004
  4. Mark Kolber
    Replies:
    4
    Views:
    340
  5. Replies:
    7
    Views:
    249
Loading...

Share This Page