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

167
Vistas
How to get form data with multi select in checkboxs - javascript

I have a form that I want to get all his values, and convert them to json object.

the problem is that I not get the multiselect fields, just one field. this is my code what I am missing?

let reportDropDowns = $('#getReport').serialize();
        reportDropDowns = decodeURI(reportDropDowns);
        let reportDropDownsJson = {};

   
    reportDropDownsJson =  JSON.parse('{"' + reportDropDowns.replace(/&/g, '","').replace(/=/g,'":"') + '"}', function(key, value) { return key===""?value:decodeURIComponent(value) });

this is my html enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Instead of serializing the data directly via .serialize(), you should instead use .serializeArray() to get the data as an array. You can then manipulate the array into an object/JSON. Try this

let reportDropDownsJson = {};
$('#getReport').serializeArray().forEach(({name, value}) => {
    if( reportDropDownsJson.hasOwnProperty(name) ){
        if( !Array.isArray(reportDropDownsJson[name]) ){
            reportDropDownsJson[name] = [reportDropDownsJson[name]];
        }
        
        reportDropDownsJson[name].push(value);
    }else{
        reportDropDownsJson[name] = value;
    }
});
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