hi,
i have two drop down list.
First one is populated from database and its working fine.
Second one will also be populated from database but as per the value selected from the first drop-down list.

<head>
<script type="text/javascript">
function xyz_list()
{
 
// xyz_list is the id of ;;my first drop-down list
  var xyz_list=document.getElementById("mob_list");
  brand=xyz_list.options[mob_list.selectedIndex].text;
 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 &&amp;amp; xmlhttp.status==200)
    {
    document.getElementById("xyz").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","XYZ.php?brand=" + brand,true);
xmlhttp.send();
}
</script>
</head>
 
<body>
<form>
<select id="xyz" onfocus="xyz_list()">
<OPTION VALUE=All>All 
<?php echo $options?> 
</SELECT> 
</form>
</body>

Below is the xyz.php script

<?php 
$brand=$_GET['brand']; 
//alert($brand); 
 
 //below is just inserting a blank value in drop list 
 $options_mobile.="<OPTION VALUE=abc>".$brand.'</option>'; 
$con = mysql_connect('localhost', 'root', ''); 
if (!$con) 
  { 
  die('Could not connect: ' . mysql_error()); 
  } 
 
mysql_select_db("mobile1", $con); 
 
 
$sql="SELECT xyz FROM abc where pqr= '$brand'"; 
 
$result = mysql_query($sql); 
$options.="<OPTION VALUE=\"$result\">".$result.'</option>'; 
while($row = mysql_fetch_array($result)) 
  { 
 // $xyz=$row["xyz"];  
  $xyz=$row["xyz"]; 
   $options.="<OPTION VALUE=\"$xyz\">".$xyz.'</option>'; 
 } 
mysql_close($con); 
?>

I am new to both of the languages, but i know wat my code wants to do. i googled a lot to find the error, But i cant figure out where i am wrong.
Any help will be highly appreciated.

Hmm... I hesitate to jump in here as my suggestion will only complicate things (since you're new to both languages).

The way you need to do this is via ajax calls to xyz.php and have it return json strings.

Also if you're new to javascript, you'll wanna use jquery or prototype for your javascript framework as either one will handle the vast majority of cross browser issues.

If you send me your private email I'll give you some example code using prototype.js for the ajax calls and to manage the triggers so when one of the selects change the other gets populated.

If it is inserting a blank, then the error is most likely in your javascript, sending a blank value. Put an alert after line 8, to determine the value of brand , so you know it is set correctly, before using it in your request. (Maybe because var is missing before brand )

The second thing that is missing, is an echo statement in your XYZ.php. If you do an AJAX call to that file, the response will be what the script outputs, which in your case is nothing.

Hmm... I hesitate to jump in here as my suggestion will only complicate things (since you're new to both languages).

The way you need to do this is via ajax calls to xyz.php and have it return json strings.

Also if you're new to javascript, you'll wanna use jquery or prototype for your javascript framework as either one will handle the vast majority of cross browser issues.

If you send me your private email I'll give you some example code using prototype.js for the ajax calls and to manage the triggers so when one of the selects change the other gets populated.

Thanks for the reply..
my email-id:- [snipped]
Thanks in advance for the sample code. I really need it.

If it is inserting a blank, then the error is most likely in your javascript, sending a blank value. Put an alert after line 8, to determine the value of brand , so you know it is set correctly, before using it in your request. (Maybe because var is missing before brand )

The second thing that is missing, is an echo statement in your XYZ.php. If you do an AJAX call to that file, the response will be what the script outputs, which in your case is nothing.

hi pritaes
i already checked with the alert box in javascript and in that its working fine.
also i have included some dummy output like $options_mobile.="<OPTION VALUE>Choose11".'</option>'; in php file. its too working fine.

so, dont know, what to do next.
Thanks for the reply.

Please remember the forum rules regarding help via email. The forums are here for all to participate and benefit from. If the questions are posted here, let's keep the solutions here as well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.