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

224
Vistas
¿Cómo crear la opción de selección dinámica HTML a partir del hash JSON?

Tengo un código de valor de prueba $ simple:

 $test = A,bb,100|A,ff,200|A,ee,100|D,ee,3|D,gg,10|R,ii,7

Tengo una etiqueta de selección en mi HTML:

 <select name="datas" id="datas"></select>

Necesito una forma sencilla de crear un cuadro de selección HTML a partir de este JSON, así:

 <select> <option value="">A</option> <option value="100">bb</option> <option value="200">ff</option> <option value="100">ee</option> </select> <select> <option value="">D</option> <option value="3">ee</option> <option value="10">gg</option> </select> <select> <option value="">R</option> <option value="7">ii</option> </select>
about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Menciona JSON, una select preexistente y la etiqueta "php", aunque no veo cómo ninguna de esas cosas es relevante para su pregunta.

Consulte el código a continuación para producir una select con su contenido, según sus requisitos:

 // This isn't JSON. It's just a string let $test = "A,bb,100|A,ff,200|A,ee,100|D,ee,3|D,gg,10|R,ii,7"; // Split the initial string where there are | characters and then loop // over the resulting array of strings $test.split("|").forEach(function(values){ // Create a new `select` element const sel = document.createElement("select"); // Split the part of the string that contains the next level // values and loop over them values.split(",").forEach(function(value){ // Create an `option` element const opt = document.createElement("option"); opt.textContent = value; // Set the value to the individual string sel.appendChild(opt); // Append the option to the select }); document.body.appendChild(sel); // Add the select to the page. });

about 4 years ago · Santiago Gelvez 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