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

240
Vistas
Using Select2 to run a function in javascript

I am using Select2 for making a dropdown and using the dropdown to run a particular code for a particular option.

Initialised my select2 with the 3 options:

$("#tags").select2({tags:["name", "job_title", "gender"]});

Now here is my function:

    _get_employee_data: function(events){
        console.log(events.target.value);
        this._rpc({
            route: '/get/parent/employee_new',
        }).then(function (result) {
            tags = $('#tags').val();
            if (tags=="name"){
                console.log(tags);
                //$('#_name').empty();
                $('#_name').append(result['name']);
            }
            else if(tags=="job_title") {
                //$('#_job_title').empty();
                $('#_job_title').append(result['job_title']);
            }
            else if(tags=="gender"){
                //$('#hello').empty();
                $('#_gender').append(result['gender']);
            }
          
        })

Now, when I select only name it ll show the names. When I select job_title and remove the previous name tag, it ll show the names and job_titles(good). But if I select 2 or multiple options and click submit it won't work. I ll have to remove the previous tag name or gender and enter only one value to use the function.

How can I select multiple options??

One way is obviously using If Else for all my conditions but it's not feasible since the tags are around 5-10 so won't be really possible to use if-else for all variations.

Any help is appreciated. Thanks.

For some reason Can't use select2 above 4.0, causing issues with the whole setup so need alternative. Still if there is a way using Select2>4.0 that would be appreciated as well.

about 4 years ago · Juan Pablo Isaza
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