Help select

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

    Help select

    Hello,
    I have definited two select: main, secondary

    main = 0, 1, 2

    secondaryA = "a", "b", "c"
    secondaryB = "1", "2", "3"
    secondaryC = "5", "6", "15", "25"

    i want that, if i check from first select (main) the value 0, in secondary
    select, will be displayed the value from secondaryA; if i set value 1, in
    secondaty, will be displayed: secondaryB etc etc... shortly:

    select 1 select 2
    main(1) ==> secondaryA
    main(2) ==> secondaryB
    main(3) ==> secondaryC


    who help me, for solve this problem?
    thanks you, cooper.


    PS: Sorry for my english


  • Vjekoslav Begovic

    #2
    Re: Help select

    Something like this:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <html>
    <head>
    <script language="JavaS cript" type="text/javascript">
    <!--
    secondaryA = new Array("a", "b", "c");
    secondaryB = new Array("1", "2", "3");
    secondaryC = new Array("5", "6", "15", "25");

    function main_changed(){
    var obj = document.getEle mentById("main" );
    var selectedValue = obj.options[obj.options.sel ectedIndex].value;
    var temp;
    switch (selectedValue) {
    case "1":
    temp = secondaryA;
    break;
    case "2":
    temp = secondaryB;
    break;
    case "3":
    temp = secondaryC;
    break;
    }
    displaySecondar y(temp);
    }

    function displaySecondar y(whichArray){
    var obj = document.getEle mentById("secon dary");
    deleteOptions(o bj);
    for (var i = 0; i<whichArray.le ngth; i++){
    var objOption = document.create Element("OPTION ");
    obj.appendChild (objOption);
    objOption.value = i;
    var newText = document.create TextNode(whichA rray[i]);
    objOption.appen dChild(newText) ;
    }
    }

    function deleteOptions(o bj){
    var l = obj.options.len gth;
    for (var i=0; i<l; i++){
    obj.options[0].removeNode(tru e);
    }
    }

    //-->
    </script>
    </head>

    <body>
    <select id="main" onchange="main_ changed();">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    </select>
    <select id="secondary"> </select>
    <script language="JavaS cript" type="text/javascript">
    <!--
    displaySecondar y(secondaryA);
    //-->
    </script>

    </body>
    </html>


    "Cooper" <cooper@bluewar e.it> wrote in message
    news:U1jLa.1550 55$pR3.3544064@ news1.tin.it...[color=blue]
    > Hello,
    > I have definited two select: main, secondary
    >
    > main = 0, 1, 2
    >
    > secondaryA = "a", "b", "c"
    > secondaryB = "1", "2", "3"
    > secondaryC = "5", "6", "15", "25"
    >
    > i want that, if i check from first select (main) the value 0, in secondary
    > select, will be displayed the value from secondaryA; if i set value 1, in
    > secondaty, will be displayed: secondaryB etc etc... shortly:
    >
    > select 1 select 2
    > main(1) ==> secondaryA
    > main(2) ==> secondaryB
    > main(3) ==> secondaryC
    >
    >
    > who help me, for solve this problem?
    > thanks you, cooper.
    >
    >
    > PS: Sorry for my english
    >
    >[/color]


    Comment

    Working...