I want to retrieve record based on two dropdown using by ajax

below code is used ajax to retrieve data based on one drop down(works fine)
but i need to use two drop down how to pass two dropdown value

<html>
<head>
<script type=“text/javascript”>
function showUser(str,str1)
{
if (str==“”)
{
document.getElementById(“txtHint”).innerHTML=“”;
return;
}
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”,“user1.php?q=”+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<form>
<select name=“users” onchange=“showUser(this.value)”>
<option value=“”>Select a person:</option>
<option value=“15”>15</option>
<option value=“2”>Lois Griffin</option>
<option value=“3”>Glenn Quagmire</option>
<option value=“4”>Joseph Swanson</option>
</select>

<select name=“users1” onchange=“showUser(this.value)”>
<option value=“”>Select a person:</option>
<option value=“1”>1</option>

</select>

</form>
<br />
<div id=“txtHint”><b>Person info will be listed here.</b></div>

</body>
</html>

below is user1.php code
<?php
$q=$_GET[“q”];

$con = mysql_connect(‘localhost’, ‘root’, ‘’);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}

mysql_select_db(“tesjoomlaautogua”, $con);

$sql=“SELECT * FROM news2 WHERE id = '”.$q."’ ";

$result = mysql_query($sql);

echo “<table border=‘1’>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
</tr>”;

while($row = mysql_fetch_array($result))
{
echo “<tr>”;
echo “<td>” . $row[‘title’] . “</td>”;
echo “<td>” . $row[‘cname’] . “</td>”;
echo “<td>” . $row[‘pname’] . “</td>”;
echo “<td>” . $row[‘title1’] . “</td>”;
echo “<td>” . $row[‘desc’] . “</td>”;
echo “</tr>”;
}
echo “</table>”;

mysql_close($con);
?>

Right. Lets bug hunt.


function showUser(str,str1)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
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","user1.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person/option>
<option value="15">15</option>
<option value="2">Lois Griffin</option>
<option value="3">Glenn Quagmire</option>
<option value="4">Joseph Swanson</option>
</select>

<select name="users1" onchange="showUser(this.value)">
<option value="">Select a person/option>
<option value="1">1</option>

Problem #1:

<select name="users1" onchange="showUser([COLOR="#0000FF"]this.value[/COLOR])">
function showUser([COLOR="#0000FF"]str,str1[/COLOR])

You’re submitting one value to a function that expects 2 parameters.

I wouldnt actually submit any values as parameters, and instead use the getElementById (and then give the selects ID’s) to pull the data on change.

Problem #2:

xmlhttp.open("GET","user1.php[COLOR="#0000FF"]?q="+str[/COLOR],true);

Where’s your second value in that url string?