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

141
Views
Filling a select list with a string or an object

this is my first post, i am a javascript newbie, and english is not my native language, so sorry if i my explanations are not as you expect.

So, i am trying to populate a select list with the result of an ajax database query. the query returns a string:

'[["Saphir","1","10"],["Serval","2","10"],["Sygma","3","10"],["Swan","4","10"]]'

My purpose is to use this result to populate a select list with e.g. for the first option: Saphir as the text, and "1" for the value.

Here is my last code, no error returned by the Chrome console. I have tried to adapt so many others found here and there, but i still didn't succeed yet. this code fills a list, but doesn't allow any selection.

enter image description here

#bfLabel410is the select list ID

function ff_sidefab_action(element, action) {
  switch (action) {
    case 'change':
      jQuery.ajax(
        {
          type: "POST",
          url: "/BMWK1census/ajaxsidemodelist.php",
          data: { code: ff_getElementByName('sidefab').value },
          success: function (data) {
            var obj = JSON.parse(data);
            console.log(obj);
            var result = [];
            var keys = Object.keys(obj);
            console.log(typeof keys)
            keys.forEach(function (key) { result.push(obj[key]); });
            jQuery('#bfLabel410').empty();
            jQuery('#bfLabel410').append(jQuery('<option>', { value: '', text: 'Choisir une option' }));
            for (var i = 0; i < result.length; i++) {
              console.log(result[i]);
              alert(result[i][0]);
              jQuery('#bfLabel410').append(jQuery('<option>', { value: result[i][1], text: result[i][0] }));
            } // fin boucle for
          } // fin success
        } // fin params ajax
      ); // fin jQuery.ajax()
      break;
    default: ;
  } // fin switch
}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

jQuery('#bfLabel410').append(jQuery('<option value="">' + 'Choisir une option' + '</option>' ));
for (var i = 0; i < result.length; i++) {
   console.log(result[i]);
   alert(result[i][0]);
   jQuery('#bfLabel410').append(jQuery('<option value="' + result[i][1] + '">' + result[i][0] + '</option>'));
} 
about 4 years ago · Juan Pablo Isaza Report
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!