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

188
Visualizações
how to display value in a dependent select box with jQuery in a CRUD table

So I have this CRUD table that looks like this: enter image description here

and when I click "Modifier", I want to display row data in all my inputs and select boxes in this enter image description here

Wilaya and Commune means State and City, you can guess that I'm trying to display the selected values from a row table in these select options.

<select name="state" id="state" onchange="populate(this.id,'city')">
    <?php foreach($Wilaya as $wilaya){
        echo '<option value="'.$wilaya.'">'.$wilaya.'</option>';
    }?>
</select>

<select name="city" id="city">
    <option value="" disabled selected>-- Selectionner Commune --</option>
</select>

and populate function looks like this:

function populate(s1,s2){
    var s1 = document.getElementById(s1);
    var s2 = document.getElementById(s2);

    s2.innerHTML = "";
    
    // here I have a bunch of if statement here one example
     if(s1.value == "Tindouf"){
        var optionArray = ['Oum el Assel','Tindouf',];
    }
     for(var option in optionArray){
       var data = optionArray[option];
       var newoption = document.createElement("option");
 
       newoption.value = data;
       newoption.innerHTML = data;
       s2.options.add(newoption);
    }
 };

this what the dropdown menu looks like after I click "Modifier" city select box.

So I do realize that populate function shows city options only when I change my selection, how can I display city options after data is loaded in the modal knowing that state value is already there but it doesn't show its cities.

enter image description here

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