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

148
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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