How to disable a multiple selection control using javascript

Discussion in 'Javascript' started by ggk517@gmail.com, Feb 27, 2006.

  1. Guest

    I have a script like below:

    ------------------------------------------------------------------------------------------------------------------------

    <html>
    <head>
    <title>TEST</title>
    <script language="javascript>
    <!--
    function masking () {
    var aForm = window.document.aForm;
    if (aForm.build_type.value == "A")
    aForm.selected_ae.disabled = true;
    else
    aForm.selected_ae.disabled = false;
    }
    // -->
    </script>
    </head>
    <body>
    <form method="post" name="aForm">
    <select name="build_type" size=1 onchange="masking()">
    <option value="A">STD</option>
    <option value="B">NON-STD</option>
    </select>
    <select name="selected_ae[]" size="3" multiple>
    <option value="james">James</option>
    <option value="john">John</option>
    <option value="jimmy">Jimmy</option>
    <option value="jason">Jason</option>
    </select>
    </form>
    </body>
    </html>

    ------------------------------------------------------------------------------------------------------------------------

    I tried to disable a multiple selection control using Javascript but it
    did not work. Can anyone please help me? Thanks in advance for your
    help.
    , Feb 27, 2006
    #1
    1. Advertising

  2. Matt Kruse Guest

    wrote:
    > I tried to disable a multiple selection control using Javascript but
    > it did not work. Can anyone please help me? Thanks in advance for your
    > help.


    Several things need fixed:

    > <script language="javascript>


    <script type="text/javascript">

    > <!--


    Don't use this

    > function masking () {
    > var aForm = window.document.aForm;
    > if (aForm.build_type.value == "A")
    > aForm.selected_ae.disabled = true;
    > else
    > aForm.selected_ae.disabled = false;
    > }


    function masking(o) {
    var isA = (o.options[o.selectedIndex].value=="A");
    o.form.elements['selected_ae[]'].disabled = isA;
    }

    > // -->


    Don't use this

    > <select name="build_type" size=1 onchange="masking()">


    <select name="build_type" size="1" onchange="masking(this)">

    Make the above changes and your code will both work and be better written.
    Hope that helps.

    --
    Matt Kruse
    http://www.JavascriptToolbox.com
    http://www.AjaxToolbox.com
    Matt Kruse, Feb 27, 2006
    #2
    1. Advertising

  3. Guest

    Thanks a lot for your help, Matt.
    It really works!!!
    , Feb 28, 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. Simon Niederberger
    Replies:
    2
    Views:
    16,497
    Christian Kaufhold
    Jan 7, 2005
  2. Andrew Crowe
    Replies:
    1
    Views:
    4,459
    Andrew Crowe
    Sep 13, 2004
  3. curiousity

    HOWTO autopost the selection list upon selection

    curiousity, Nov 21, 2003, in forum: ASP .Net Mobile
    Replies:
    0
    Views:
    266
    curiousity
    Nov 21, 2003
  4. Loebb
    Replies:
    0
    Views:
    199
    Loebb
    Feb 23, 2004
  5. Replies:
    1
    Views:
    208
Loading...

Share This Page