how to disable options in an option list?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fluffy Convict

    how to disable options in an option list?

    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.getE lementById("myO ptionList")
    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="disabled Option"> 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!
  • Evertjan.

    #2
    Re: how to disable options in an option list?

    Fluffy Convict wrote on 05 dec 2004 in comp.lang.javas cript:
    [color=blue]
    > 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.getE lementById("myO ptionList")
    > x.disabled=true
    >}
    >
    > But what if I just want to disable one option, or two - so that this
    > option cannot be clicked / selected anymore?[/color]

    disabled, style.display and style.visibilit y do not work as expected.

    You could remove an option dynamically:


    <form name="testform" >
    <select name="testselec t" id="testselect" >
    <option value="first">f irst option</option>
    <option value="second"> second option</option>
    <option value="third">t hird option</option>
    </select>
    </form>



    <script type='text/javascript'>
    var node = document.getEle mentById('tests elect');

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

    removeOption(1)
    </script>

    Comment

    Working...