ok, you're right, here is my code, in one hand it works for special case, only when i'm having many corps in categories, but in other hand there are many problems:
1.the listbox grade does not appear at all.
2.when i'm having one corps the other listbox does not appear.
<html>
<head>
<title>Document sans nom</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language = "Javascript">
function ChangeCategorie()
{
document.frmHierarchy.hid_Categorie_Changed.value = "True"
document.frmHierarchy.hid_Corps_Changed.value = "True"
document.frmHierarchy.hid_Cadre_Changed.value = "True"
document.frmHierarchy.lstCadre.value = "000"
document.frmHierarchy.lstCorps.value = "000"
document.frmHierarchy.lstGrade.value = "000"
document.frmHierarchy.submit()
}
function ChangeCorps()
{
document.frmHierarchy.hid_Corps_Changed.value = "True"
document.frmHierarchy.hid_Cadre_Changed.value = "True"
document.frmHierarchy.hid_Grade_Changed.value = "True"
document.frmHierarchy.lstCadre.value = "000"
document.frmHierarchy.lstGrade.value = "000"
document.frmHierarchy.submit()
}
function ChangeCadre()
{
document.frmHierarchy.hid_Cadre_Changed.value = "True"
document.frmHierarchy.hid_Grade_Changed.value = "True"
document.frmHierarchy.lstGrade.value = "000"
document.frmHierarchy.submit()
}
function ChangeGrade()
{
document.frmHierarchy.hid_Grade_Changed.value = "True"
document.frmHierarchy.submit()
}
</script>
</head>
<body>
<?
include("connexion.php");
//****************************************************
$strSQL = "SELECT * FROM TAB_CATEG ORDER BY cod_categ DESC";
$result_categ=mssql_query($strSQL);
$strCategorie = $_POST['lstCategorie'];
if (empty($strCategorie)){
if ($rsCategorie = mssql_fetch_array($result_categ))
$strCategorie = $rsCategorie['COD_CATEG'];
mssql_data_seek($result_categ, 0);
}
//'***********************************************************
if ($strCategorie!="") {
$strSQL = "SELECT * FROM TAB_Corps WHERE COD_CATEG ='$strCategorie' ";
$result_corps=mssql_query($strSQL);
if ($rsCorps = mssql_fetch_array($result_corps)) {
$strCorps = $_POST['lstCorps'];
if ((empty($strCorps)) ||( $_POST['hid_Categorie_Changed'] == "True")) {
if ($rsCorps=mssql_fetch_array($result_corps)){
$strCorps = $rsCorps['COD_CORPS'];
mssql_data_seek($result_corps, 0);
}
}
}
//****************************************
$strSQL = "SELECT * FROM TAB_Cadre WHERE COD_CORPS='$strCorps' and COD_CATEG ='$strCategorie' ";
$result_cadre=mssql_query($strSQL);
$strCadre= $_POST['lstCadre'];
if ((empty($strCadre)) || ($_POST['hid_Corps_Changed']=="True") || ($_POST['hid_Categorie_Changed']=="True")){
if ($rsCadre=mssql_fetch_array($result_cadre))
$strCadre = $rsCadre['COD_CADRE'];
mssql_data_seek($result_cadre, 0);
}
//'***********************************************************
$strSQL = "SELECT * FROM TAB_GRADE WHERE COD_CORPS='$strCorps' and COD_CATEG ='$strCategorie' and COD_CADRE='$strcadre' ";
$result_grade=mssql_query($strSQL);
$strGrade= $_POST['lstGrade'];
if (empty($strGrade) || $POST['hid_Corps_Changed']== "True" ||$POST['hid_Categorie_Changed']== "True" || $_POST['hid_grade_Changed']== "True"){
if ($rsGrade = mssql_fetch_array($result_grade))
$strGrade= $rsGrade['COD_GRADE'];
}
} ?>
<form name="frmHierarchy" method="POST" action="listbox1.php">
<INPUT TYPE=hidden NAME=hid_Categorie_Changed size="20">
<INPUT TYPE=hidden NAME=hid_Corps_Changed size="20">
<INPUT TYPE=hidden NAME=hid_Cadre_Changed size="20">
<INPUT TYPE=hidden NAME=hid_Grade_Changed size="20"><P>
<TABLE>
<tr>
<td>
<SELECT id=lstCategorie name="lstCategorie" LANGUAGE=javascript onchange="return ChangeCategorie()">
<?
//' Add the Categorie to the list
while($rsCategorie=mssql_fetch_array($result_categ)){
$strCategorie = $rsCategorie['LIB_CATEG'];
if ($rsCategorie['COD_CATEG'] == $_POST['lstCategorie']) { ?>
<OPTION VALUE="<? echo $rsCategorie['COD_CATEG']?>" SELECTED><? echo $strCategorie ?></OPTION>
<? //$LibCategorie=$rsCategorie["LIB_CATEG"]?>
<? }
else { ?>
<OPTION VALUE="<? echo $rsCategorie['COD_CATEG'] ?>" ><? echo $strCategorie ?></OPTION>
<?
}
}
mssql_data_seek($result_categ, 0);
?>
</SELECT>
<input type=hidden name="LibCategorie" size="23" value="<? echo $LibCategorie ?>"></TD>
</TR>
<tr>
<td>
<SELECT id=lstCorps name="lstCorps" LANGUAGE=javascript onchange="return ChangeCorps()" >
<?
//' Add the Corps to the list
// mssql_data_seek($result_corps,0);
if ($strCorps!=""){
while($rsCorps =mssql_fetch_array($result_corps)) {
//mssql_data_seek($result_corps,0);
$strCorps = $rsCorps['LIB_CORPS'];
if ($rsCorps['COD_CORPS'] == $_POST['lstCorps']) {?>
<OPTION Value="<? echo $rsCorps['COD_CORPS']?>" SELECTED> <? echo strtolower($strCorps) ?></OPTION>
<? //$LibCorps=$rsCorps["LIB_CORPS"]?>
<? }
else
{
?>
<OPTION Value="<? echo $rsCorps['COD_CORPS']?>" > <? echo strtolower($strCorps) ?></OPTION>
<? }
}
}
mssql_data_seek($result_corps, 0);
?>
</SELECT>
</TR>
<tr>
<td>
<SELECT id=lstCadre name=lstCadre LANGUAGE=javascript onchange="return ChangeCadre()" >
<? //$LibCadre=$rsCadre["LIB_CADRE"];
//' Add the Cadre to the list
while($rsCadre=mssql_fetch_array($result_cadre)){
$strCadre = $rsCadre['LIB_CADRE'];
if ($rsCadre['COD_CADRE'] == $_POST['lstCadre']){
?>
<OPTION Value="<? echo $rsCadre['COD_CADRE']?>" SELECTED><? echo $strCadre ?></OPTION>
<? }
else
{
?>
<OPTION Value="<? echo $rsCadre['COD_CADRE'] ?>"><? echo $strCadre ?></OPTION>
<?
}
}
mssql_data_seek($result_cadre, 0);
?>
</SELECT>
</TR>
<tr>
<td>
<SELECT id=lstgrade name="lstGrade" LANGUAGE=javascript onchange="return ChangeGrade()" >
<?
//' Add the Grade to the list
while($rsGrade=mssql_fetch_array($result_grade)){
$strGrade = $rsGrade['LIB_GRADE'];
if ($rsGrade['COD_GRADE'] == $_POST['lstGrade']) {
?>
<OPTION Value="<? echo $rsGrade['COD_GRADE'] ?>" SELECTED><? echo $strGrade ?></OPTION>
<? }
else
{
?>
<OPTION Value="<? echo $rsGrade['COD_GRADE'] ?>"><? echo $strGrade ?></OPTION>
<?
}
}
mssql_data_seek($result_grade, 0);
?>
</SELECT>
<?
mssql_close($sqlconnect) or die("Impossible de fermer la base");
mssql_free_result(result_categ);
mssql_free_result(result_corps);
mssql_free_result(result_cadre);
mssql_free_result(result_grade);
?>
</TR>
</table>
</form>
</body>
</html>