Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

239
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!