Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在jsp中向Combobox动态添加值_Jsp - Fatal编程技术网

在jsp中向Combobox动态添加值

在jsp中向Combobox动态添加值,jsp,Jsp,如何将数据库值添加到同一jsp页面中另一个组合框的选定索引更改事件上的组合框中 请快来帮忙 这是我的密码 <tr> <td>Item</td> <td> <select name="cboItems" id="cboItems"> <option v

如何将数据库值添加到同一jsp页面中另一个组合框的选定索引更改事件上的组合框中 请快来帮忙

这是我的密码

<tr>
                    <td>Item</td>
                    <td>
                        <select name="cboItems" id="cboItems">
                            <option value="-1">--Select--</option>
                            <%
                                CommodityInfoActions comObj = new CommodityInfoActions(erpConn);
                                comObj.getAllRecords();
                                Iterator itr = comObj.ListOfObjects.iterator();
                                int i = 1;
                                while (itr.hasNext()) {
                                    CommodityInfo newObj = (CommodityInfo) itr.next();
                                    String item = newObj.getCommodityName();
                                    long itemid = newObj.getId();
                                    out.println("<option value='" + itemid + "' >" + item + "</option>");
                                    i++;
                                }

                            %>
                        </select>                                
                    </td>
                </tr>
                <tr>
                    <td>Batch No. </td>
                    <td>
                        <select id="cboBatchNo">
                            <option>--select--</option>
                            <%
                                try {
                                    if (Long.parseLong(request.getParameter("cboItems")) > -1) {
                                        CommodityPriceActions comp = new CommodityPriceActions(erpConn);
                                        comp.getBatchno(Long.parseLong(request.getParameter("cboItems")));
                                        CommodityPrices comPrice = new CommodityPrices();
                                        itr = comp.ListOfObjects.iterator();
                                        i = 1;
                                        while (itr.hasNext()) {
                                            CommodityPrices newObj = (CommodityPrices) itr.next();

                                            out.println("<option value='" + newObj.getId() + "'>" + newObj.getBatchNo() + "</option>");
                                        }
                                    }
                                } catch (Exception exc) {
                                }
                            %>

                        </select>
                    </td>                        
                </tr>

我不想在运行时根据在cboItems中选择的选项更改cboBatchno的内容…

@ddMyth2857356我真的不知道您尝试了什么?这是提示

$('#combobox1').change(function(){
var id = $(this).val();
   $.ajax({
    url : "servlet_URL&id="+ id,
    type : "POST",
    success : function(data) {
        $("#combobox2").html(data);
    }
});
});

这是其中一个想法。你想出了你尝试过的和你面临的问题?希望这有帮助。

您可以将onchange事件添加到combobox1,通过ajax发送请求,并将来自ajax的成功数据填充到Combox2。您可以帮助我指定数据部分吗。@ddMyth2857356您可以通过requset.getparameterid在servlet中接收id,并使用该值查询表。最后,使用jsp页面像值一样组合数据。然后,jQueryAjax将负责填充第二个组合框。