Ola pessoal sou novo em php, to construindo um sisteminha web e me deparei com esse problema, to tentando fazer 2 combobox um de estado ou tro de cidade, onde no momento que eu escolher o estado,o combox da cidade seja preenchido com as cidades referentes ao estado, segue meu código: <?
include "conexao.php";
$sql = "SELECT * FROM uf ORDER BY iduf";
$res = mysql_query($sql,$conexao);
$num = mysql_num_rows($res);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="prototype.js"></script>
<script language="javascript">
function CarregaCidades(iduf)
{
if(iduf){
var myAjax = new Ajax.Updater('cidadeAjax','carrega_cidades.php?iduf='+iduf,
{
method : 'post',
});
}
}
</script>
</head>
<body>
<table width="300" border="0" align="center" cellpadding="2" cellspacing="1">
<tr>
<td width="88">Estado:</td>
<td width="212">
<select name="estado" id="estado" onchange="CarregaCidades(this.value)">
<? for($i=0;$i<$num;$i++)
{
$dados = mysql_fetch_array($res);
?>
<option value <? echo $dados['iduf']?>><? echo $dados['nome_uf']?></option>
<? }?>
</select>
</td>
</tr>
<tr>
<td>Cidade:</td>
<td><div id="cidadeAjax">
<select name="cidade" id="cidade">
<option value="">Selecione o estado</option>
</select>
</div></td>
</tr>
</table>
</body>
</html>
carrega cidades.PHP
<?
include "conexao.php";
$iduf = $_POST['iduf'];
$sql = "SELECT m.nome_muni,m.idmunicipio FROM municipio m inner join uf u on m.uf = u.iduf where uf = $iduf";
$res = mysql_query($sql,$conexao);
$num_cidades = mysql_num_rows($res);
?>
<select name="cidade" id="cidade">
<? for($j=0;$j<$num_cidades;$j++){
$dados = mysql_fetch_array($res);
?>
<option value="<?echo $dados['idmunicipio']?>"><? echo $dados['nome_muni']?></option>
<? }?>
</select>