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 8488181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:27:42+00:00 2026-06-10T21:27:42+00:00

I am trying to pass values from a multiple select listbox through Ajax to

  • 0

I am trying to pass values from a multiple select listbox through Ajax to PHP. I saw some examples in Jquery and JSON, however I am trying to accomplish this just in plain old javascript (Ajax). Here is what I have so far (simplified):

Ajax:

function chooseMultiEmps(str)
  {
    var mEmpList2 = document.getElementById('mEmpList'); //values from the multi listbox
    for (var i = 0; i < mEmpList2.options.length; i++) //loop through the values
    var mEmpList = mEmpList2.options[i].value;  //create a variable to pass in string
    if (window.XMLHttpRequest)
    {
       xmlhttp = new XMLHttpRequest();
    }
    else
    {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function()
   {
   if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
   {
      //specific selection text
      document.getElementById('info').innerHTML = xmlhttp.responseText; 
   }
  }
  xmlhttp.open("POST", "myPage.php", true);
  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  var queryString = "&mEmpList=" + mEmpList; //query string should have multiple values
  xmlhttp.send(queryString);
}

I can run an alert(mEmpList) and get each value in individual message boxes, however when I retrieve and echo the $_POST['mEmpList'], I get only the first value. Also, when I alert(queryString), I get only one value.

I think I need to create a comma delimited array, and then pass that through the query string. From there, I can use the PHP implode/explode feature to separate the values. Any assistance would be greatly appreciated.

  • 1 1 Answer
  • 0 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-06-10T21:27:44+00:00Added an answer on June 10, 2026 at 9:27 pm

    here:

    for (var i = 0; i < mEmpList2.options.length; i++) //loop through the values
    var mEmpList = mEmpList2.options[i].value;  //create a variable to pass in string
    

    you are redefining your mEmpList over and over again, that means only the last value is send

    You could do:

    var mEmpList = '';
    for (var i = 0; i < mEmpList2.options.length; i++) { //loop through the values
        mEmpList = mEmpList +','+ mEmpList2.options[i].value;  //create a variable to pass in string
    }
    

    Also your queryString is not ok, no need for &

    var queryString = "mEmpList=" + mEmpList;
    

    That way at the end you will have all values delimite by comma ,

    In PHP you can use explode to loop each value:

    <?php
        $string = explode(',' $_GET['mEmpList']);
        for($i=1; $i<count($string); $i++){
            echo $string[$i]."<br />";
        }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good evening guys, I'm trying to pass multiple checkbox values through AJAX and process
I'm trying to pass multiple values from PHP into my javascript function. The function
i am trying to pass two values to php file via ajax my code
I'm trying to change some php code so that i get my values from
I'm trying to pass multiple checkboxes with different values to a PHP script that
I'm trying to pass to a javascript function some values from my Java Applet
I am trying to pass values from a ruby hash to a bash script..
I am trying to pass a value from php to javascript. I understand one
I'm trying to pass an Int value pulled from a JSON String to reduce
I'm an encryption novice trying to pass some values back and forth between systems.

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.