duanchuopi2298 2015-10-08 15:00
浏览 33

从php中的下拉列表中获取结果

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥15 帮我写一个c++工程