Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda