0

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.

4
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by Ezzaral
1

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.

0

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.

Edited by pritaeas: n/a

0

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.

Edited by Ezzaral: Snipped email. Please keep it on site.

0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.