Select control question in Javascript

Discussion in 'Javascript' started by Carl Wu, Nov 8, 2003.

  1. Carl Wu

    Carl Wu Guest

    Hi all,

    I am newcomer in HTML, Javascript,

    I want to create two select controls S1, S2.

    There are 3 options: ALL, A, B in S1;

    When select A in S1, It let you select A1, A2 in S2,

    Where select B in S1, It let you select B1, B2 in S2;

    When select ALL in S1, It let you select A1, A2, B1, B2 in S2

    The default selection in S1 is ALL,

    Can somebody give me some suggestion?

    Thanks advance

    Carl
    Carl Wu, Nov 8, 2003
    #1
    1. Advertising

  2. Carl Wu wrote:

    > I want to create two select controls S1, S2.


    <select name="S1">
    </select>

    <select name="S2">
    </select>

    > There are 3 options: ALL, A, B in S1;


    <select name="S1">
    <option>ALL</option>
    <option>A</option>
    <option>B</option>
    </select>

    > When select A in S1, It let you select A1, A2 in S2,
    >
    > Where select B in S1, It let you select B1, B2 in S2;
    >
    > When select ALL in S1, It let you select A1, A2, B1, B2 in S2


    <script type="text/javascript" language="JavaScript">
    <!--
    function enableItems(o)
    {
    if (!o || !o.form || !o.form.elements)
    return false;

    var
    o2 = o.form.elements['S2'],
    a1 = o2.options[0],
    a2 = o2.options[1],
    b1 = o2.options[2],
    b2 = o2.options[3];

    if (o2 && a1 && typeof a1.disabled != "undefined")
    {
    switch (o.selectedIndex)
    {
    case 0: // ALL
    a1.disabled = false;
    if (a2)
    a2.disabled = false;
    if (b1)
    b1.disabled = false;
    if (b2)
    b2.disabled = false;
    break;

    case 1: // A
    a1.disabled = false;
    if (a2)
    a2.disabled = false;
    break;

    case 2: // B
    if (b1)
    b1.disabled = false;
    if (b2)
    b2.disabled = false;
    }
    }
    }
    //-->
    </script>
    <form action="...">
    <select name="S1" onchange="enableItems(this)">
    <option>ALL</option>
    <option>A</option>
    <option>B</option>
    </select>

    <select name="S2">
    <option>A1</option>
    <option>A2</option>
    <option>B1</option>
    <option>B2</option>
    </select>
    </form>

    Untested.

    > The default selection in S1 is ALL,


    It is the default because it is the first item.

    > Can somebody give me some suggestion?


    See above. And before you post to a newsgroup the next time, you should get
    a minimum clue of what you are doing (by reading documentations, FAQS aso.)
    This is not a support forum but a discussion group.


    PointedEars
    Thomas 'PointedEars' Lahn, Nov 8, 2003
    #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. =?Utf-8?B?Y3JhaWdAYW10ZGF0YXRlY2hub2xvZ2llcw==?=

    Drop Down List Control , Select Value, and Javascript

    =?Utf-8?B?Y3JhaWdAYW10ZGF0YXRlY2hub2xvZ2llcw==?=, Sep 25, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    11,004
    Jéjé
    Sep 25, 2005
  2. Lisa Calla
    Replies:
    0
    Views:
    256
    Lisa Calla
    Nov 9, 2004
  3. palmiere
    Replies:
    1
    Views:
    325
    Erwin Moller
    Feb 9, 2004
  4. Bonge Boo!
    Replies:
    5
    Views:
    180
    Bonge Boo!
    Apr 25, 2005
  5. frey
    Replies:
    0
    Views:
    85
Loading...

Share This Page