How to send the multiple values selected from list box to ajax

Hi
all

I am using the list box to send the data to server using ajax and getting the response.

Here is the code

<script type=“text/JavaScript”>

function showUser(str)
{

if (str.length==0)
{
document.getElementById(‘txtHint’).innerHTML=“”;
return;
}

var url=“/tim/kerproject/phpforms/facultyajax.php”;
url=url+“?q=”+str;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(‘txtHint’).innerHTML=xmlhttp.responseText;
}
}
//xmlhttp.open(“GET”,“ajatest2.php?q=”+str,true);
xmlhttp.open(“GET”,url,true);
xmlhttp.send();
}

</script>

<?php

include(“config1.php”);
$result=mysql_query(“select batch_id from batch_master”);

echo “<select name=‘batchid’ id=‘batchid’ onchange=‘showUser(this.value)’>”;
echo “<option value=‘’>Select </option>”;

while($row=mysql_fetch_array($result))
 {
   $bat=$row['batch_id'];
   echo "&lt;option value='$bat'&gt;$bat";
   }

echo"</select>";

echo"<br />“;
echo”<div id=‘txtHint’>“;
echo”</div>";

?>

In this list box we can select single value and send it to ajax.

Now I want to select multiple values from the listbox and send it to ajax.

please help me out

Thanks

MD.Samiuddin

You would want to use a select box with the multiple attribute enabled, and replace the onchange event with a button’s onclick event instead.

Have a look at the following demo I put together, hopefully it makes sense otherwise let me know and I’ll explain what it does.

Dear Paul

Thanks a lot for your help. I will check this code and get back to you.

You’re welcome Chris. :slight_smile: