List box problem

nareshmp
03:06:11

Hi,

I have problem in linking two list boxes in PHP using Ajax & Mysql.
My coding:


<html>
<body>

<script type="text/javascript">
function AjaxFunction(brand_id)
{
var httpxml;
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;
}
}
}
function stateck()
{
if(httpxml.readyState==4)
{

var myarray=eval(httpxml.responseText);
// Before adding new we must remove previously loaded elements
for(j=document.testform.subcat.options.length-1;j>=0;j--)
{
document.testform.subcat.remove(j);
}


for (i=0;i<myarray.length;i++)
{
var optn = document.createElement("OPTION");
optn.text = myarray[i];
optn.value = myarray[i];
document.testform.subcat.options.add(optn);

}
}
}
var url="dd1.php";
url=url+"?brand_id="+brand_id;
url=url+"&sid="+Math.random();
httpxml.onreadystatechange=stateck;
httpxml.open("GET",url,true);
httpxml.send(null);
}
</script>

<form name="testform" method='POST' action='mainck1.php'>Name:<input type=text name=fname>
Select first one <select name=cat onChange="AjaxFunction(this.value);">
<option value='select one'>Select One</option>

<?
require "config.php";// connection to database
$q=mysql_query("select * from brand ");
while($n=mysql_fetch_array($q)){
echo "<option value=$n[brand_id]>$n[brand]</option>";
}

?>
</select>

<select name=subcat>

</select><input type=submit value=submit>
</form>

</body>
</html>


Kindly give some ideas to sort out this issue.

Regards,
Naresh
cabalsdemon
06-09-2012
add some information to another table in your database called items with data rows id item and brand
and call it in your second mysql query
$brand=$_REQUEST['brand']; //the brand POST from your form
$q1=mysql_query("select * from item where brand='$brand'");


<select name=subcat> <!--or call it the name you want -->
<?while($n1=mysql_fetch_array($q1)){
echo "<option value=$n1[item]>$n[item]</option>";
}
</select><input type=submit value=submit>
Please Login to post your reply or start a new topic