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

153
Views
select multiple values in select2 using javascript

I need to pass value from select2 to javscript. But its not working.

this is my html code

<select  class="txtTeamAddDelete form-control" name="itemName"></select>
</div>
<button type="button" class="btnrowAddDelete">Add New Row</button>

This is my javascript select2

<script type="text/javascript">
$('.txtTeamAddDelete').select2({
  placeholder: 'Select an item',
  ajax: {
    url: "{{route('meeting.list-meeting.dataAjax')}}",
    dataType: 'json',
    delay: 250,
    processResults: function (data) {
      return {
        results:  $.map(data, function (item) {
              return {
                  text: item.name,
                  id: item.id,
                  email: item.email
              }
          })
      };
    },
    cache: true
  }
});
</script>

this is js for display select2 data

    $(document).ready(function(){
        $('.btnrowAddDelete').click(function(){
        var txtTeamAddDelete = $('.txtTeamAddDelete').find(':selected').text();
        $('.TableAddDelete tbody').append("<tr><td>"+txtTeamAddDelete+"</td><td>"+email+"</td></tr>");
        });
    });

its working to fetch name data but not email. I want to fetch two data: email & name. i already tried this

var txtTeamAddDelete = $('.txtTeamAddDelete').select2('val',["name", "email"]);

but it return undefined

i want to show it like this. can someone help me. Thanks!

enter image description here

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!