Chained Dropdown Menu in Magento not working

186 views Asked by At

I am searching for like 3 days for a resolution but i am unable to get the final part to make it possible.

My Problem is that I can't establish the dependency between my 3 Menus.

This means that options of C should be dependent on value selected in B and options of B must be dependent on value selected in A. i.e. a->b->c

I only get the Menu a -> b, but not b -> c.

If someone can give me a new code to work with, where i only have to put in the options.

That's my code:

<html>

<head>
  <style type="text/css">
  </style>

  <script language="Javascript">
    <!-- Start 
    function update_auswahl1() {
        var speicher;
        var auswahl1 = document.forms.verzeichnis.auswahl1;
        var auswahl2 = document.forms.verzeichnis.auswahl2;
        var auswahl3 = document.forms.verzeichnis.auswahl3;
        auswahl2.options.length = 0; // DropDown Menü entleeren 
        auswahl3.options.length = 0; // DropDown Menü entleeren 

        //********************** AUSWAHL 1 ****************************************************************

        if (auswahl1.options[auswahl1.selectedIndex].value == "a") {
          auswahl2.options[0] = new Option("d");
          auswahl2.options[1] = new Option("e");
        } else if (auswahl1.options[auswahl1.selectedIndex].value == "b") {
          auswahl2.options[0] = new Option("e");
          auswahl2.options[1] = new Option("f");
        } else if (auswahl1.options[auswahl1.selectedIndex].value == "c") {
          auswahl2.options[0] = new Option("f");
          auswahl2.options[1] = new Option("g");
        } else if (auswahl1.options[auswahl1.selectedIndex].value == "") {
          auswahl2.options[0] = new Option("---- Bitte waehlen ----");
        }


        //*************************************************************************************************

        //********************* AUSWAHL 2 *****************************************************************   

        if (auswahl2.options[auswahl2.selectedIndex].values == "d") {
          auswahl3.options[0] = new Option("h");
          auswahl3.options[1] = new Option("i");
          auswahl3.options[2] = new Option("j");
        } else if (auswahl2.options[auswahl2.selectedIndex].values == "e") {
          auswahl3.options[0] = new Option("i");
          auswahl3.options[1] = new Option("j");
          auswahl3.options[2] = new Option("k");
        } else if (auswahl2.options[auswahl2.selectedIndex].values == "f") {
          auswahl3.options[0] = new Option("k");
          auswahl3.options[1] = new Option("l");
          auswahl3.options[2] = new Option("m");
        }
      }
      //*************************************************************************************************
      // Ende -->
  </script>
  <title>Unbenanntes Dokument</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
  <form name="verzeichnis">
    <select size="1" name="auswahl1" onChange="update_auswahl1()">
      <option value="" selected>---- Bitte w&auml;hlen ----</option>
      <option value="a">a</option>
      <option value="b">b</option>
      <option value="c">c</option>
    </select>
    <br>
    <br>
    <select size="1" name="auswahl2">
      <option selected>---- Bitte w&auml;hlen ----</option>
    </select>
    <br>
    <br>
    <select name="auswahl3" size="1">
      <option selected>---- Bitte w&auml;hlen ----</option>
    </select>
  </form>

</body>

</html>

I am thankful 4 every help

1

There are 1 answers

2
Alexey Rytikov On BEST ANSWER

You made 3 mistakes:

  1. In if-else block "AUSWAHL 2" you type ".values" instead of ".value"

    (auswahl2.options[auswahl2.selectedIndex].values == "d")

  2. You have not add the handler on select auswahl2.
  3. Need to write 2 functions instead of 1, otherwise when you change auswahl2, he will be overwritten without storing the selected value.
<html>

<head>
  <style type="text/css">
  </style>

  <script language="Javascript">
    <!-- Start 
    function update_auswahl1() {
        var speicher;
        var auswahl1 = document.forms.verzeichnis.auswahl1;
        var auswahl2 = document.forms.verzeichnis.auswahl2;
        var auswahl3 = document.forms.verzeichnis.auswahl3;
        auswahl2.options.length = 0; // DropDown Menü entleeren 
        auswahl3.options.length = 0; // DropDown Menü entleeren 

        //********************** AUSWAHL 1 ****************************************************************

        if (auswahl1.options[auswahl1.selectedIndex].value == "a") {
          auswahl2.options[0] = new Option("d");
          auswahl2.options[1] = new Option("e");
        } else if (auswahl1.options[auswahl1.selectedIndex].value == "b") {
          auswahl2.options[0] = new Option("e");
          auswahl2.options[1] = new Option("f");
        } else if (auswahl1.options[auswahl1.selectedIndex].value == "c") {
          auswahl2.options[0] = new Option("f");
          auswahl2.options[1] = new Option("g");
        } else if (auswahl1.options[auswahl1.selectedIndex].value == "") {
          auswahl2.options[0] = new Option("---- Bitte waehlen ----");
        }

        update_auswahl2();
        //*************************************************************************************************
    }

      function update_auswahl2() {
        var speicher;
        var auswahl2 = document.forms.verzeichnis.auswahl2;
        var auswahl3 = document.forms.verzeichnis.auswahl3;
        auswahl3.options.length = 0; // DropDown Menü entleeren 

        //********************* AUSWAHL 2 *****************************************************************   
        if (auswahl2.options[auswahl2.selectedIndex].value == "d") {
          auswahl3.options[0] = new Option("h");
          auswahl3.options[1] = new Option("i");
          auswahl3.options[2] = new Option("j");
        } else if (auswahl2.options[auswahl2.selectedIndex].value == "e") {
          auswahl3.options[0] = new Option("i");
          auswahl3.options[1] = new Option("j");
          auswahl3.options[2] = new Option("k");
        } else if (auswahl2.options[auswahl2.selectedIndex].value == "f") {
          auswahl3.options[0] = new Option("k");
          auswahl3.options[1] = new Option("l");
          auswahl3.options[2] = new Option("m");
        }
      }
      //*************************************************************************************************
      // Ende -->
  </script>
  <title>Unbenanntes Dokument</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
  <form name="verzeichnis">
    <select size="1" name="auswahl1" onChange="update_auswahl1()">
      <option value="" selected>---- Bitte w&auml;hlen ----</option>
      <option value="a">a</option>
      <option value="b">b</option>
      <option value="c">c</option>
    </select>
    <br>
    <br>
    <select size="1" name="auswahl2" onChange="update_auswahl2()">
      <option selected>---- Bitte w&auml;hlen ----</option>
    </select>
    <br>
    <br>
    <select name="auswahl3" size="1">
      <option selected>---- Bitte w&auml;hlen ----</option>
    </select>
  </form>

</body>

</html>