Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
Cascading Multiselect Option List using Javascript

I have found code online that satisfies my need of cascading option list. But I also need to make multiple selections. When I add multiple to select tag it allows me to make multiple selections. However it shows as if only 1 option was choosed. Here is the code I am using:

Javascript:

var root_1_Object = {{ url_categories|safe }}
window.onload = function() {
var root_1_Sel = document.getElementById("root_1");
var root_2_Sel = document.getElementById("root_2");
var root_3_Sel = document.getElementById("root_3");

for (var x in root_1_Object) {
    root_1_Sel.options[root_1_Sel.options.length] = new Option(x, x);
}
root_1_Sel.onchange = function() {
    //empty root_3_S- and root_2_S- dropdowns
    root_3_Sel.length = 1;
    root_2_Sel.length = 1;
    //display correct values
    for (var y in root_1_Object[this.value]) {
        root_2_Sel.options[root_2_Sel.options.length] = new Option(y, y);
    }
}
root_2_Sel.onchange = function() {
    //empty root_3_S dropdown
    root_3_Sel.length = 1;
    //display correct values
    var z = root_1_Object[root_1_Sel.value][this.value];
    for (var i = 0; i < z.length; i++) {
    root_3_Sel.options[root_3_Sel.options.length] = new Option(z[i], z[i]);
    }
    console.log(root_3_Sel);

}
}

Html:

                <select name="root_1" id="root_1" multiple required/>
                    <option value="" selected="selected"></option>
                </select>
                <br><br>

                
                <select name="root_2" id="root_2" multiple required/>
                    <option value="" selected="selected"></option>
                </select>
                <br><br>

                
                <select name="root_3" id="root_3" multiple required/>
                    <option value="" selected="selected"></option>
                </select>
                <br><br> 
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda