Hello, I got the following code from someone and have tailored it to fit my needs but I have a problem. The first menu populates from my MySQL database. However, when the first menu is selected, the second menu will not populate with the correct information. Zero is the only number that comes up. I think I have all the queries correct but I'll let everyone take a look at it.

Here's the main page:

<html>
<head>
<title>Roshan's Triple Ajax dropdown code</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript" type="text/javascript">
// Roshan's Ajax dropdown code with php
// This notice must stay intact for legal use
// Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com
// If you have any problem contact me at http://roshanbh.com.np
function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
    }
	
	function getYear(makeid) {		
		
		var strURL="findState.php?make="+makeid;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('statediv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
	function getModel(makeid,yearid) {		
		var strURL="findCity.php?make="+makeid+"&year="+yearid;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('citydiv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
				
	}
</script>
</head>
<body>
<form method="post" action="" name="form1">
<table width="60%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="150">Make</td>
    <td  width="150">

<?php
$link = mysql_connect('localhost', 'root', '1964vette'); //changet the configuration in required
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('productionfigures');
$query="SELECT id,makename FROM makes";
$result=mysql_query($query);

?>

<select name="makes" onChange="getYear(this.value)">
	<option>Select Make</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value=<?=$row['id']?>><?=$row['makename']?></option>
<? } ?>
        </select></td>
  </tr>
  <tr style="">
    <td>Year</td>
    <td ><div id="statediv"><select name="years" >
	<option>Select Make First</option>
        </select></div></td>
  </tr>
  <tr style="">
    <td>Model</td>
    <td ><div id="citydiv"><select name="models">
	<option>Select Year First</option>
        </select></div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</form>
</body>
</html>

Here is findstate.php:

<!--//---------------------------------+
//  Developed by Roshan Bhattarai    |
//	http://roshanbh.com.np           |
//  Contact for custom scripts       |
//  or implementation help.          |
//  email-nepaliboy007@yahoo.com     |
//---------------------------------+-->
<?
#### Roshan's Ajax dropdown code with php
#### Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com
#### if you have any problem contact me at http://roshanbh.com.np
#### fell free to visit my blog http://roshanbh.com.np
?>

<? $makeid=intval($_GET['makes']);
$link = mysql_connect('localhost', 'root', '1964vette'); //changet the configuration in required
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('productionfigures');
$query="SELECT * FROM years WHERE makeid='$makeid'";
$result=mysql_query($query);

?>
<select name="years" onchange="getModel(<?=$make?>,this.value)">
<option>Select Year</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value=<?=$row['id']?>><?=$row['yearname']?></option>
<? } ?>
</select>

And finally here is findcity.php:

<!--//---------------------------------+
//  Developed by Roshan Bhattarai    |
//	http://roshanbh.com.np           |
//  Contact for custom scripts       |
//  or implementation help.          |
//  email-nepaliboy007@yahoo.com     |
//---------------------------------+-->
<?
#### Roshan's Ajax dropdown code with php
#### Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com
#### if you have any problem contact me at http://roshanbh.com.np
#### fell free to visit my blog http://php-ajax-guru.blogspot.com
?>

<? $makeid=intval($_GET['makes']);
$yearid=intval($_GET['years']);
$link = mysql_connect('localhost', 'root', '1964vette'); //changet the configuration in required
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('productionfigures');
$query="SELECT id, modelname FROM models WHERE makeid='$makeid' AND yearid='$yearid'";
$result=mysql_query($query);
?>

<select name="models">
<option>Select Model</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value><?=$row['modelname']?></option>
<? } ?>
</select>

Any help would be appreciated!!

Arthur

I dont have the time to look at all your code, however I did notice that part of your script uses short PHP tags: <? instead of <?php

Try changing these and test again (this has been a problem encountered several times by myself).


SoniaBaby

This article has been dead for over six months. Start a new discussion instead.