需要javascript来在下拉列表中调用隐藏值

时间:2014-12-30 09:56:47

标签: javascript php jquery mysql

我有2个下拉列表,仓库和位置(在我的编码中称为子软件)。

仓库是父级,位置是子级。 我想要的是,例如,当用户点击仓库ddl时, 结果将显示:

  • 新加坡
  • 马来西亚

当用户点击[新加坡]时, 位置将显示:

  • 伍德兰
  • 巴旺

**如何让我的位置显示仓库结果?

 function einv_generateWarehouseDropdown($warehouse,$field,$subwarehouse)
    {
        //connect to database
        base_connectDatabase();
        echo "<select id=\"".$field."\" name=\"".$field."\"  style=\"width:300px\" onChange=\"getSubjDesc(this.value);showSubWarehouseDetails(this.value)\" onfocus=\"getSubjDesc(this.value);showSubWarehousehouseDetails(this.value)\">";

        //if (isset($warehouse)) {
        if (isset($warehouse) && ($warehouse != "")) {
            $warehousename = einv_getWarehouseDetail($warehouse);
            echo "<option value=\"". $warehouse ."\">". $warehousename['einv_wh_name'] ."</option>";
        } else {
            $warehouse = 0;
        }

        $getWarehouseSQL = base_executeSQL("SELECT * FROM einv_warehouse where einv_wh_id<>" . $warehouse . " 
        ORDER BY einv_wh_name");
        while($warehousedata_row = base_fetch_array($getWarehouseSQL)){
            if (base_num_rows($getWarehouseSQL)!= 0) {
                echo "<option value=\"". $warehousedata_row['einv_wh_id'] ."\">". $warehousedata_row['einv_wh_name']."</option>";
            }
        }
        echo  "</select>";

        $subwarehouse = "";
        $getSubWarehouseSQL = base_executeSQL("SELECT * FROM einv_subwarehouse  ORDER BY einv_whs_name");
        while($subwarehousedata_row = base_fetch_array($getSubWarehouseSQL)){
            if (base_num_rows($getSubWarehouseSQL)!= 0) {
                $subwarehouse.="<input type=hidden name='lstsubj_DESC_".$subwarehousedata_row['einv_whs_wh_id']."[]' id='lstsubj_DESC_".$subwarehousedata_row['einv_whs_id']."' value='".$subwarehousedata_row['einv_whs_id']."|||".$subwarehousedata_row['einv_whs_name']."'>\n";
                //$subwarehouse.="<input type=hidden name='lstcomp_DESC_".$subwarehousedata_row['einv_whs_wh_id']."[]' id='lstcomp_DESC_".$subwarehousedata_row['einv_whs_id']."' value='".$subwarehousedata_row['einv_whs_id']."'>\n";
            }
        }
        echo $subwarehouse;

        //close the database
        base_closeDatabase();
    }

    function einv_generateSubWarehouseDropdown($subwarehouse,$field)
    {
        //connect to database
        base_connectDatabase();

        $subwarehouse = NULL;
        echo "<select id=\"".$field."\" name=\"".$field."\"  style=\"width:200px\">";
    //  onChange=\"getSubjDesc(this.value);showSubWarehouseDetails(this.value)\" onfocus=\"getSubjDesc(this.value);showSubWarehousehouseDetails(this.value)\">";


        if (isset($subwarehouse))
        {
            $subwarehousename = einv_getSubWarehouseDetail($subwarehouse);
            echo "<option value=\"". $subwarehouse ."\">". $subwarehousename['einv_whs_name'] ."</option>";
            //$subwarehouse.="<input type=hidden name='lstsubj_DESC_".$subwarehouse."' id='lstsubj_DESC_".$subwarehouse."' value='".$subwarehousename['einv_whs_name']."'>\n";
            //$subwarehouse.="<input type=hidden name='lstcomp_DESC_".$subwarehouse."' id='lstcomp_DESC_".$subwarehouse."' value='".$subwarehousename['einv_whs_id']."'>\n";
        }elseif(!isset($subwarehouse))
        {
            $subwarehouse = 0;
        }
        echo "SELECT * FROM einv_subwarehouse where einv_whs_id<>" . $subwarehouse . " 
        ORDER BY einv_whs_name";
        $getSubWarehouseSQL = base_executeSQL("SELECT * FROM einv_subwarehouse where einv_whs_id<>". $subwarehouse . " 
        ORDER BY einv_whs_name");
             while($subwarehousedata_row = base_fetch_array($getSubWarehouseSQL))
             if (base_num_rows($getSubWarehouseSQL)!= 0)
             {
                 echo "<option value=\"". $subwarehousedata_row['einv_whs_id'] ."\">". $subwarehousedata_row['einv_whs_name']."</option>";
                // $subwarehouse.="<input type=hidden name='lstsubj_DESC_".$subwarehousedata_row['einv_whs_id']."' id='lstsubj_DESC_".$subwarehousedata_row['einv_whs_id']."' value='".$subwarehousedata_row['einv_whs_name']."'>\n";
                // $subwarehouse.="<input type=hidden name='lstcomp_DESC_".$subwarehousedata_row['einv_whs_id']."' id='lstcomp_DESC_".$subwarehousedata_row['einv_whs_id']."' value='".$subwarehousedata_row['einv_whs_id']."'>\n";
             }
        echo  "</select>";
        echo $subwarehouse;


        //close the database
        base_closeDatabase();
        }

1 个答案:

答案 0 :(得分:0)

对于该链式功能,您可能需要Ajax。在没有ajax的情况下执行此操作的简单方法是使用data属性:

<select id="parent">
    <option value="1">Parent 1</option>
</select>

<select id="child">
    <option data-parentid="1">Child 1 from Parent 1</option>
</select>

然后您执行change事件以显示隐藏所需的子选项。

为简洁起见,省略了代码。请查看Fiddle

顺便说一句,这只是一个例子。您必须在代码上实现它。祝你好运。