Page 1 of 1

Ajax retuned List Box cannot select multiple value

Posted: Thu Oct 23, 2008 3:25 am
by khalidmehmoodawan
hi all,

here is the scenario :banghead:
i have populated a list using ajax code. it has been populated successfully

BUT

i am unable to make this list select Multiple Values.

i.e. multiple='multiple' is not working.

here is the test code.
This is handler


<?php
require_once('./dbconn/conn.php');
$q = $_GET["q"];
$seed=$_GET['inputtxt'];
$query="";

if ($q == 1) $query="select bsFriendlyName, bsID from tabbasett where bsFriendlyname like '%" . $seed . "%'" ;
elseif ($q == 2) $query="select alarmType, id_f, idalarm from tabalarms where id_f = " . $seed ;

$recordSet = mysql_query($query) or mysql_error();
$number_of_rows = mysql_num_rows($recordSet);

if ($number_of_rows < 1)
{
echo "<div>no record found. <a href='report1.php?new=true&alarmID=false&id=" . $seed . "' onclick='document.form1.submit();'>New Alarm</a></div>";
//<br>q=". $q . "<br>inputtxt " . $seed . "<br>query = " . $query . "<br>no. of rows" . $number_of_rows;

unset($recordSet); unset($query); unset($number_of_rows);
return false;
}

if ($q == 1)
{
echo "<select name='bsSelectedList' size=\"10\" class='style1' onChange='return ListBoxSearchClicked(this);'>";
while($row=mysql_fetch_array($recordSet)){
echo "<option value=\"" . $row[bsFriendlyName] . "\" id=\"" . $row[bsID] . "\">" . $row[bsFriendlyName] . "</option>";
}
}
elseif ($q == 2)
{
echo "<select id='selectAlarms' name='selectAlarms' class='style1' onChange='return ComboBoxSearchClicked(this);'>";
echo "<option value='New Alarm' id='New Alarm' selected='selected'>New Alarm</option>";
while($row=mysql_fetch_array($recordSet)){
echo "<option value='" . $row[idalarm] . "' id=" . $row[idalarm] . ">" . $row[alarmType] . "</option>";
}
}

if ($q == 3)
{
echo "<select name='bsSelectedList' size=\"10\" class='style1' onChange='ListBoxSearchClicked(this);' multiple='multiple'>";
while($row=mysql_fetch_array($recordSet)){
echo "<option value=\"" . $row[bsFriendlyName] . "\" id=\"" . $row[bsID] . "\">" . $row[bsFriendlyName] . "</option>";
}
}


unset($recordSet); unset($query); unset($number_of_rows); unset($row);

echo "</select>";
?>



ajax function

function AjaxFunction(q, url, input_field, output_field){
httpxml=null;

try {// Firefox, Opera 8.0+, Safari
httpxml=new XMLHttpRequest();
}
catch (e){ // Internet Explorer
try {
httpxml=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try {
httpxml=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("Your browser does not support AJAX!");
return false;
}
}
} //alert ("q =" + q + "\n url = " + url + "\ninput field = " + input_field + "\noutput field = " + output_field);
httpxml.onreadystatechange=function(){
if (httpxml.readyState==4){
switch (q)
{
case 1 :
document.getElementById("captionSearchResults").innerHTML="Search Results for <b><u class='style2'>'" + input_field.value + "'</u></b>";
document.getElementById("searchResultsCell").innerHTML=httpxml.responseText;
break;
case 2: document.getElementById("selectAlarmsCell").innerHTML=httpxml.responseText;
break;

case 3 :
document.getElementById("captionSearchResults").innerHTML="Search Results for <b><u class='style2'>'" + input_field.value + "'</u></b>";
document.getElementById("searchResultsCell").innerHTML=httpxml.responseText;
break;
}
}
};
httpxml.open("GET",url,true);
httpxml.send(null);
}

Re: Ajax retuned List Box cannot select multiple value

Posted: Thu Oct 23, 2008 3:44 am
by novice4eva
have you checked for the value of $q, maybe it is not equal to 3. Only when you have $q==3, you are echoing select with attribute multiple.

Re: Ajax retuned List Box cannot select multiple value

Posted: Thu Oct 23, 2008 4:24 am
by khalidmehmoodawan
yeah man i m a bit :crazy:

the value of $q was 2 . soooooo stupid of me.

any wayz thanks a lot.