php / JS / Jquery + JCombo
Bonjour,
Je débute en php/JS et j'essaie de réaliser deux select imbriqués (menu deroulant). J'utilise pour cela jQuery + JCombo.
Cela marche pour le premier menu deroulant mais rien pour le 2e.
Après plusieurs tests, il semble que le problème soit au niveau du passage/récupération par $_GET.
Mon HTML > OK a priori
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
Fournisseur : <select id="fournisseur"></select> <br/><br/>
Article : <select id="article"></select> <br/><br/>
<script type="text/javascript">
$("#fournisseur").jCombo("formE_GetFournisseur.php", {
initial_text: "-- Choisir un fournisseur --" // initial option
} );
$("#article").jCombo("formE_GetArticle.php?id=", {
parent: "#fournisseur",
initial_text: "-- Choisir un article --" // initial option
} );
</script> |
formE_GetFournisseur.php > OK
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
<?php
include("fonctions.php");
ConnectMaBase();
$sql = 'SELECT DISTINCT fournisseur FROM articles ORDER BY fournisseur LIMIT 0,99';
$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
$items = array();
if($req && mysql_num_rows($req)>0) {
while($row = mysql_fetch_array($req)) {
$items[] = array( $row[0], $row[0] );
}
}
mysql_free_result ($req);
mysql_close();
echo json_encode($items);
?> |
formE_GetArticle.php > KO
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
<?php
include("fonctions.php");
ConnectMaBase();
$fournisseur = $_GET['id'];
$sql = 'SELECT nom FROM articles WHERE fournisseur = ".'$fournisseur'." ORDER BY nom LIMIT 0,99';
$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
$items = array();
if($req && mysql_num_rows($req)>0) {
while($row = mysql_fetch_array($req)) {
$items[] = array( $row[0], $row[0] );
}
}
mysql_free_result ($req);
mysql_close();
echo json_encode($items);
?> |