hi ,
i'm having troubles with 3 dependent dynamic lisbox.I have 3 tables:
the tab_categori (cod_categ,lib_categ)
tab_corps(cod_categ, cod_corps, lib_corps)
tab_cadre (cod_categ,cod_corps,cod_cadre,lib_cadre)
i'm trying to pop the listbox from the first table, when i chose the lib_categ the listbox corps change automaticaly.Then i choose the corps, but it does not selected, because $corps is empty and i dont know why!!
Here is the code
<script language = "Javascript">
function grade(){
document.changergrade.submit()
}
</script>
</head>
<body>
<form method="post" action="grade.php" name="changergrade">
<input type="hidden" name="categorie" value="<? echo $_POST['categorie'] ; ?>">
<table>
<tr>
<td align=right><div align="right">Select the categori: </div></td>
<td> <p>
<?php
include("connexion.php");
$sqlquery_categ ="SELECT * FROM TAB_CATEG";
$result_categ=mssql_query($sqlquery_categ);
echo('<select name="categorie" LANGUAGE=javascript onchange="return grade()" size="1">');
mssql_data_seek($result_categ, 0);
$row=mssql_fetch_array($result_categ);
if (empty($_POST['categorie'])) $categorie=$row['COD_CATEG'];
else
$categorie=$_POST['categorie'];
mssql_data_seek($result_categ, 0);
while($row=mssql_fetch_array($result_categ)) {?>
<option value="<? echo $row['COD_CATEG']?>" <? if ($categorie==$row['COD_CATEG']) echo ('selected');?>> <? echo $row['LIB_CATEG']?> </option>
<?
}
echo('</select>');
?>
</p></td>
</tr>
<td align=right><p align="right">Select the corps :
<td align=right><div align="left">
<p>
<?
if (empty($categorie)){
$sqlquery_corps="SELECT * FROM Tab_Corps";
$result_corps=mssql_query($sqlquery_corps) or die ("impossible d'executer la requete");
echo('<select name="corps" LANGUAGE=javascript onchange="return grade()" size="1">');
while($row1=mssql_fetch_array($result_corps)){
?>
<div align="center">
<option value="<? echo $row1['COD_CORPS']?>" selected><? echo $row1['LIB_CORPS']?></option>
<?
}
echo('</select>');
}else
{
$corps=$_POST['corps'];
echo $corps;
$sqlquery_corps="SELECT LIB_CORPS FROM Tab_Corps,TAB_CATEG WHERE TAB_CATEG.COD_CATEG='$categorie' and TAB_CATEG.COD_CATEG=Tab_Corps.COD_CATEG ";
$result_corps=mssql_query($sqlquery_corps) or die ("impossible d'executer la requete");
echo('<select name="corps" LANGUAGE=javascript onchange="return grade()" size="1" >');
while($row=mssql_fetch_array($result_corps)){
?>
<option value="<? echo $row['COD_CORPS']?>" <? if ($corps==$row['COD_CORPS']) echo ('selected');?>><? echo $row['LIB_CORPS']?></option>
<?
}
echo('</select>');
}
?>
</p></td>
</tr>
mssql_close($sqlconnect) or die("Impossible de fermer la base");
mssql_free_result(result_corps);
mssql_free_result(result_categ);
?>