doupo5178 2019-02-13 05:01
浏览 73

显示或隐藏用户使用Javascript选择的特定下拉列表

Hi I have two dropdown forms (but you need to start typing before the suggested word shows), the first dropdown called "Products" then the second one is called "Goods", I want that if the user chooses a Products Dropdown, the Goods Dropdown will be hidden and the Fieldrequire will also be false. Vice Versa If the user chooses a Goods Dropdown, the Products Dropdown wil be hidden and the Fieldrequire will be false. Please Help me to solve this problem. I have seen the same problem with mine, but none of them worked for me

here is the Product dropdown Code:

<?php if( (!isset($_POST["quickAddOnly"])) || "NO" == "NO"  ){  ?>
                    <tr style="">
                        <td valign=top class="tb" scope="row"> <label for="Product">Product</label> <span class="required" style="color:red" >*</span> </td>
            <td valign=top>:</td>
            <td scope="row">
                    <?php
                $keyrow = getProductsFilters(array_qval( $data, "product_id" , "" ),"name");
                $forid = "";
                $forid .= $keyrow["raw_name"];        
                    ?>
                                    <input  fieldError="Place a valid Product"    fieldRequire="yes"  type="hidden" name="product_id" id="Product"   value="<?php echo trim(array_qval( $data, "product_id" , "" ));?>"/>       
                                    <input  value="<?php echo $forid;?>" type="text" name="dropdown_product_id" autocomplete="off" style="width:297px; background-color: #f5f5f5" /><br /><small>start typing for suggestive dropdown menu of Products  Name</small>
                                    <script language="javascript">
                                        $(document).ready(function(){
                                           $("<?php echo $useform;?>input[name=dropdown_product_id]").each(function(){
                        $(this).dblclick( function(){
                            $(this).autocomplete( "search");
                        });
                                                $(this).autocomplete({
                                                                source: function( request, response ) {
                                                                                 var lddText = "";
                                                                                $.ajax({
                                            type: "POST",
                                                                                        url: "products/xml/autocompleteProducts.php",
                                                                                        dataType: "json",
                                                                                        data: {
                                                                                             val : request.term,
                                                                                             field : "name|sku",
                                                                                             lookup : "id",
                                                                                             ldd : lddText
                                                                                        },
                                                                                        success: function( data ) {
                                                                                                response( data );
                                                                                        }
                                                                                });
                                                                        },
                                                                minLength: 0,
                                                                select: function( event, ui ) {
                                                                        $(this).siblings("input[name=product_id]:first").val(ui.item.id).trigger("change");
                                                                        $(this).addClass("input-ok").removeClass("input-ajax");
                                                                },
                                close: function(event, ui) {
                                    if( $(this).siblings("input[name=product_id]:first").val() == "" || $(this).siblings("input[name=product_id]:first").val() == 0)
                                    {
                                        $(this).removeClass("input-ok");
                                    }
                                    $(this).removeClass("input-ajax");
                                },
                                search: function(event, ui) {
                                    $(this).addClass("input-ajax");
                                    $(this).siblings("input[name=product_id]:first").val("");
                                }
                                                });
                                            })
                                        });
                                    </script>
                    </td>
                    </tr>
         <?php }  ?>

and Here is the Goods Dropdown Code :

 <!-- start of goods_info -->
             <?php if( (!isset($_POST["quickAddOnly"])) || "NO" == "NO"  ){  ?>
                    <tr style="">
                        <td valign=top class="tb" scope="row"> <label for="Goods">Goods</label> <span class="required" style="color:red" >*</span> </td>
            <td valign=top>:</td>
            <td scope="row">
                    <?php
                $keyrow = getGoods_InfoFilters(array_qval( $data, "goods_id" , "" ),"name");
                $forid = "";
                $forid .= $keyrow["raw_goods_info_name"];        
                    ?>
                                    <input  fieldError="Place valid Goods"    fieldRequire="yes"  type="hidden" name="goods_id" id="Goods"   value="<?php echo trim(array_qval( $data, "goods_id" , "" ));?>"/>     
                                    <input         value="<?php echo $forid;?>" type="text" name="dropdown_goods_id" autocomplete="off" style="width:297px; background-color: #f5f5f5" /><br /><small>start typing for suggestive dropdown menu of Products  Name</small>
                                    <script language="javascript">
                                        $(document).ready(function(){
                                           $("<?php echo $useform;?>input[name=dropdown_goods_id]").each(function(){
                        $(this).dblclick( function(){
                            $(this).autocomplete( "search");
                        });
                                                $(this).autocomplete({
                                                                source: function( request, response ) {
                                                                                 var lddText = "";
                                                                                $.ajax({
                                            type: "POST",
                                                                                        url: "goods_info/xml/autocompleteGoods_Info.php",
                                                                                        dataType: "json",
                                                                                        data: {
                                                                                             val : request.term,
                                                                                             field : "name|upteam_sku",
                                                                                             lookup : "id",
                                                                                             ldd : lddText
                                                                                        },
                                                                                        success: function( data ) {
                                                                                                response( data );
                                                                                        }
                                                                                });
                                                                        },
                                                                minLength: 0,
                                                                select: function( event, ui ) {
                                                                        $(this).siblings("input[name=goods_id]:first").val(ui.item.id).trigger("change");
                                                                        $(this).addClass("input-ok").removeClass("input-ajax");
                                                                },
                                close: function(event, ui) {
                                    if( $(this).siblings("input[name=goods_id]:first").val() == "" || $(this).siblings("input[name=goods_id]:first").val() == 0)
                                    {
                                        $(this).removeClass("input-ok");
                                    }
                                    $(this).removeClass("input-ajax");
                                },
                                search: function(event, ui) {
                                    $(this).addClass("input-ajax");
                                    $(this).siblings("input[name=goods_id]:first").val("");
                                }
                                                });
                                            })
                                        });
                                    </script>
                    </td>
                    </tr>
         <?php }  ?>

         <!-- end of goods info --->
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效