Boas, criei um sistema de actualização da Combo Box, que mostra as opções na segunda combo derivadas da escolha feita na primeira combo, mas à primeira vez vem sempre com um erro, tentei fazer o ISSET, mas não deu igual:
Código :
Código :
<!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>Documento sem título</title>
<script language="javascript" type="text/javascript">
function criterio(cod_dist) {
document.frm.submit();
}
</script>
</head>
<body>
<form action="" method="post" name="frm" id="frm">
<table width="500" border="0">
<tr>
<td>Category</td>
<td>
<select name="cod_dist" id="cod_dist" onchange="criterio(this.value);">
<option value="">--Select--</option>
<?php
$sql1=mysql_query("SELECT * from distritos");
while($sql_r=mysql_fetch_assoc($sql1))
{
?>
<option value="<?php echo $sql_r["cod_dist"]; ?>"
<?php if (isset($sql_r["cod_dist"])){ if($sql_r["cod_dist"]==$_REQUEST["cod_dist"]) { echo "Selected"; } }?>><?php echo $sql_r["desig_dist"]; ?>
</option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>Company</td>
<td id="td_company">
<select name="concelhos" id="concelhos">
<option value="">--Select--</option>
<?php
$sql=mysql_query("SELECT * from concelhos where cod_dist ='".$_REQUEST[cod_dist]."'");
while($sql_res=mysql_fetch_assoc($sql))
{
?>
<option value="<?php echo $sql_res["cod_conc"]; ?>"><?php echo $sql_res["desig_conc"]; ?></option>
<?php
}
?>
</select>
</td>
</tr>
</table>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sem título</title>
<script language="javascript" type="text/javascript">
function criterio(cod_dist) {
document.frm.submit();
}
</script>
</head>
<body>
<form action="" method="post" name="frm" id="frm">
<table width="500" border="0">
<tr>
<td>Category</td>
<td>
<select name="cod_dist" id="cod_dist" onchange="criterio(this.value);">
<option value="">--Select--</option>
<?php
$sql1=mysql_query("SELECT * from distritos");
while($sql_r=mysql_fetch_assoc($sql1))
{
?>
<option value="<?php echo $sql_r["cod_dist"]; ?>"
<?php if (isset($sql_r["cod_dist"])){ if($sql_r["cod_dist"]==$_REQUEST["cod_dist"]) { echo "Selected"; } }?>><?php echo $sql_r["desig_dist"]; ?>
</option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>Company</td>
<td id="td_company">
<select name="concelhos" id="concelhos">
<option value="">--Select--</option>
<?php
$sql=mysql_query("SELECT * from concelhos where cod_dist ='".$_REQUEST[cod_dist]."'");
while($sql_res=mysql_fetch_assoc($sql))
{
?>
<option value="<?php echo $sql_res["cod_conc"]; ?>"><?php echo $sql_res["desig_conc"]; ?></option>
<?php
}
?>
</select>
</td>
</tr>
</table>
</form>
</body>
</html>