I have a problem, I would like to get a result from a dropdown in php, to fill an other one and create a cascaded dropdown. In the first dropdown, I have categories, and when I select one, I want the second dorpdown to fill automatically with the sub-categories. Here is my code:
$Categorie = new Categorie();
if ($branche_transforme == 1) {
$liste_categorie = $Categorie->getCategoriesForCdcTransforme();
}
else {
$liste_categorie = $Categorie->getCategoriesForCdc($cdc_id);
}
echo '<div class="body">';
echo '<div class="alert alert-info"><span class="glyphicon glyphicon-info-sign"></span>
Présentation de votre produit telle qu\'elle apparaîtra sur le site Sud de France.</div>';
echo '<form action="'.$action_form.'" method="POST" id="ajout_produit" enctype="multipart/form-data" >';
echo '<input type="hidden" name="next_etape" value="etape_cdc" />';
if (isset($produit_id) && !empty($produit_id) && $produit_id != 0) {
echo '<input type="hidden" name="produit_id" value="'.$produit_id.'" />';
}
echo '<input type="hidden" name="cdc_id" value="'.$cdc_id.'" />';
echo '<input type="hidden" name="branche_transforme" value="'.$branche_transforme.'" />';
echo '<table class="formul">';
echo '<tr class="champ_obligatoire"><th>Nom du produit<span class="etoile">*</span>
<span title="Pour les vins, précisez le nom de cuvée et le millésime." class="tooltip_span"><img src="img/info.png" alt="" /></span></th>
<td class="bs-example tooltip-demo"><input type="text" id="nom" name="nom" value="'.$nom.'"
onblur="verifVide(this);" class="form-control"
placeholder="Entrez le nom du produit" data-original-title=""
data-toggle="tooltip" data-placement="right" /></td></tr>';
echo '<tr class="champ_obligatoire"><th>Catégorie du produit<span class="etoile">*</span></th>';
echo '<td class="bs-example tooltip-demo"><select name="cat_parent"
onblur="verifVide(this);" class="form-control"
data-original-title="" data-toggle="tooltip" data-placement="right">';
$parent = "";
foreach($liste_categorie as $categorie) {
if ($parent != $categorie->getParentNom()) {
$parent= $categorie->getParentNom();
$value= $categorie->getParent_id();
echo '<option value="'.$value.'" >'.$parent.'</option>';
}
return $parent;
}
echo '</select></td></tr>';
echo '<th><td class="bs-example tooltip-demo"><select name="categorie_id"
onblur="verifVide(this);" class="form-control"
data-original-title="" data-toggle="tooltip" data-placement="right"></th>';
Here you have the first dropdown:
echo '<tr class="champ_obligatoire"><th>Catégorie du produit<span class="etoile">*</span></th>';
echo '<td class="bs-example tooltip-demo"><select name="cat_parent"
onblur="verifVide(this);" class="form-control"
data-original-title="" data-toggle="tooltip" data-placement="right">';
$parent = "";
foreach($liste_categorie as $categorie) {
if ($parent != $categorie->getParentNom()) {
$parent= $categorie->getParentNom();
$value= $categorie->getParent_id();
echo '<option value="'.$value.'" >'.$parent.'</option>';
}
return $parent;
}
And here is the one I want to fill with the result of the previous.
echo '</select></td></tr>';
echo '<th><td class="bs-example tooltip-demo"><select name="categorie_id"
onblur="verifVide(this);" class="form-control"
data-original-title="" data-toggle="tooltip" data-placement="right"></th>';
Honnestly, I don't know how to do. Thank you.