J'ai un menu déroulant qui appel automatiquement deux autres menus déroulants
le soucis, c'est que je n'ai que la valeur du 1er menu déroulant qui rempli ma base mysql !
Ca ne doit pas être grand chose, mais je tourne un peu en rond là !
voici le code :
ajax.js
- Code: Tout sélectionner
function ajax(strthis)
{
var param = strthis.value;
var codedial = document.getElementById("codedial").options[document.getElementById("codedial").selectedIndex].value;
$("#tr_intitule").empty();
$.ajax
(
{
type: "POST",
url: "select_intitule.php",
data: "var="+param,
success:
function(msg)
{
$("#tr_intitule").append("<td>"+ msg +"</td>");
}
}
);
var param = strthis.value;
var codedial = document.getElementById("codedial").options[document.getElementById("codedial").selectedIndex].value;
$("#tr_unite").empty();
$.ajax
(
{
type: "POST",
url: "select_unite.php",
data: "var="+param,
success:
function(msg)
{
$("#tr_unite").append("<td>"+ msg +"</td>");
}
}
);
}
form1.php
- Code: Tout sélectionner
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="ajax.js"></script>
<form method="POST" action="valide1.php" name="caapp"> <tr align="center">
<td><div align="right">Code : </div></td>
<td><div align="left"><?php include('select_codedial.php')?></div></td>
</tr>
<tr align="center">
<td><div align="right">Unité d'Emploi : </div></td>
<td><div align="left" id='tr_unite'><?php include('select_unite.php')?></div></td>
</tr>
<tr align="center">
<td><div align="right">Intitulé Code : </div></td>
<td><div align="left" id='tr_intitule'><?php include('select_intitule.php')?></div></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" value="Envoyer" /></td>
</tr>
<input type="hidden" name="id" value="<?php echo($id) ;?>">
</form>
select_codedial.php
- Code: Tout sélectionner
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="ajax.js"></script>
<select id='codedial' name='codedial' onchange="ajax(this)">
<option value='void_codedial'>-</option>
<?php
include("../connexion.php");
$query = "SELECT DISTINCT codedial FROM codedial ORDER BY codedial ASC";
$rq = mysql_query($query) or die(mysql_error());
while ($row=mysql_fetch_array($rq, MYSQL_ASSOC))
{
$codedial = $row["codedial"];
echo "<option value='$codedial'>$codedial</option>";
}
mysql_close();
?>
</select>
select_unite.php
- Code: Tout sélectionner
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="ajax.js"></script>
<select id='unite' name='unite'>
<?php
include("../connexion.php");
$var=$_POST['var'];
$query = "SELECT DISTINCT unite FROM codedial WHERE codedial='$var' ORDER BY unite ASC";
$rq = mysql_query($query) or die(mysql_error());
while ($row=mysql_fetch_array($rq, MYSQL_ASSOC))
{
$unite = $row["unite"];
echo "<option value='$unite'>$unite</option>";
}
mysql_close();
?>
</select>
select_intitule.php
- Code: Tout sélectionner
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="ajax.js"></script>
<select id='intitule' name='intitule'>
<?php
include("../connexion.php");
$var=$_POST['var'];
$query = "SELECT DISTINCT intitule FROM codedial WHERE codedial='$var' ORDER BY intitule ASC";
$rq = mysql_query($query) or die(mysql_error());
while ($row=mysql_fetch_array($rq, MYSQL_ASSOC))
{
$intitule = $row["intitule"];
echo "<option value='$intitule'>$intitule</option>";
}
mysql_close();
?>
</select>