Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7692705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:54:51+00:00 2026-05-31T20:54:51+00:00

Have looked quite hard for this answer but having no luck. I have 3

  • 0

Have looked quite hard for this answer but having no luck.

I have 3 select lists in a form. The first list is already part of the form, the second two are dynamically added. These select lists are part of an array named event_staff[].

<select name="event_staff[]" class="event_staff">
<option value="1">Mark</option>
<option value="2">Sue</option>
</select>

<select name="event_staff[]" class="event_staff">
<option value="1">Mark</option>
<option value="2">Sue</option>
</select>

<select name="event_staff[]" class="event_staff">
<option value="1">Mark</option>
<option value="2">Sue</option>
</select>

The user can select a person from each of the lists which are then to be sent via AJAX/Json to a a PHP script which iterates through the array and inserts the selected staff into the database.

For the life of me I dont know how to access the selected values of the lists and send them as an array to the PHP script.

Because the select lists are dynamically created I am not using IDs to access them. I was instead relying on accessing their values by name.

select[name='event_staff[]']

I had tried this code but the alert is returning empty:

var event_staff = new Array();
$("select[name='event_staff[]']:selected").each(function() {
event_staff.push($this).attr('value');
});
alert(event_staff);

Thanks.

Solved with the following, but not sure if its pretty or not:

var event_staff = new Array();
$('select[name="event_staff[]"] option:selected').each(function() {
event_staff.push($(this).attr('value'));
});

Just seems I needed the option:selected. While this doesnt seem to create an array, I have exploded the variable in the PHP on the delimiter and created the array that way.

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:54:52+00:00Added an answer on May 31, 2026 at 8:54 pm
    var event_staff = [];
    $("select[name='event_staff[]'] option:selected").each(function () {
        event_staff.push( this.value );
    });
    alert(event_staff);
    

    Here’s the fiddle: http://jsfiddle.net/Rx6Fk/


    If you instead want the name of that person, use .text():

    var event_staff = [];
    $("select[name='event_staff[]'] option:selected").each(function() {
        event_staff.push( $.text(this) );
    });
    alert(event_staff);
    

    Here’s the fiddle: http://jsfiddle.net/Rx6Fk/1/


    Alternatively, you could use jQuery’s .map method:

    var event_staff = $("select[name='event_staff[]'] option:selected").map(function() {
        return $.text(this);
    }).get();
    alert(event_staff);
    

    Here’s the fiddle: http://jsfiddle.net/Rx6Fk/2/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked all over but can't find an answer to this... Quite simply
I have looked into this fairly extensively, but have not found quite what I
I have looked at the answer here, but it did not quite apply: Gradle
I've looked through several posts but I haven't quite found any answers that have
I have looked around on Google and StackOverflow for the answer to this question,
I have looked but have not found a specific answer for changing just one
I have looked for an answer for this nearly every where that I can
I have got this problem: Find the first element in a list, for which
I have looked at many posts but unable to find an answer to my
I have looked for this in several places but not necessarily found the right

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.