Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!