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

147
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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