JSFiddle - React, Tailwind, and code Playground

by faissal_aboullait

JavaScript

function qp(qp,id){
                  var qpresult = qp[id];
                   }
                
                  function tarif(tarif,id){
                  var tarifresult = tarif[id];
                   }

 $(document).ready(function(){ 
   $('#salle').change(function(){ 
 //any select change on the dropdown with id salle trigger this code        
    $("#disciplines > option").remove(); //first of all clear select items
            var salle_nom = $('#salle').val();  //here i'm taking salle id of the selected one.
            $.ajax({
                type: "POST",
                url: "http://localhost/public_html/admin/dropdown_salle/get_cities/"+salle_nom, //here i'm calling our user controller and get_disciplines method with the salle_id
                dataType : "json",
                success: function(disciplines) //we're calling the response json array 'disciplines'
                {
                  var discipline = new Array();
                  var qp = new Array();
                  var tarif = new Array();
                  for (i=0; i<disciplines.length; ++i) {
// Now i got 3 arrays from the two dimentional array from the db. one for 'disciplines', one for 'qp_agent' = (pourcentage a payé pour l'agent), and the last for 'tarif'(tarif par mois de la cette discipline dans la salle choisi).
                  discipline[i] = disciplines[i].discipline+' pour '+disciplines[i].categorie_tarif;
                  qp[i] = disciplines[i].qp_agent;
                  tarif[i] = disciplines[i].tarif;
                }  
                $.each(discipline,function(id,value) 
  //here i'm doing a foeach loop round each value with id as the key and value as the value
                {
                    var opt = $('<option />'); 
  // here i'm creating a new select option with for each value
                     opt.val(id);
                     opt.text(value);
                     $('#cities').append(opt); 
                    //here i will append these...