0

我正在使用源代码进行多项选择

下拉清单

由于该示例已针对静态值显示,因此我已根据我的要求进行了编辑,并且我试图使用数据库填充下拉列表的值,这意味着将值动态填充到下拉列表中。但是,我没能做到。请帮我。下拉列表将根据从第一个下拉列表中选择的选项进行填充

<select id="design" onmouseup="showOfficer()" >
 <option value="A">A</option>
 <option value="B">B</option>
 <option value="C">C</option>
 <option value="D">D</option>
 <option value="E">E</option>
 </select>

<select id="officers" class="officers" multiple="multiple"><div id="show_officer"></div></select>

我的javascript

<script language="javascript" >
function showOfficer(){
                        document.getElementById("msg4").style.display="block";
                       $.ajax({
                            url: 'getValues.jsp',
                            data: 'design_id='+ $('#design').val(),
                            type: 'post',
                            success: function(msg){document.getElementById("show_officer").innerHTML=msg;
                                document.getElementById("msg4").style.display="none";
                            }});
                    }
</script>

获取值.jsp

<%@include file="../dbconfig.jsp" %><%
String design=request.getParameter("design_id");
 String buffer="";
 try{
     int count=0;
 ResultSet rs = state.executeQuery("SELECT OFFICER_ID,FIRST_NAME,LAST_NAME FROM OFFICER WHERE STATUS_TYPE='UNASSIGN' AND DESIGN_ID='"+design+"'");//
   while(rs.next()){
   buffer=buffer+"<option value='"+rs.getString(1)+"'>"+rs.getString(2)+" "+rs.getString(1)+"</option>";
   count++;
   }
 if(count==0)
     {
  buffer=buffer+"<option value='ERROR'>OFFICERS ASSIGNED ALREADY</option>";
 }
 }
 catch(Exception e){
    buffer=buffer+"<option value='ERROR'>OFFICERS ASSIGNED ALREADY</option>"+e;
 }
 buffer=buffer+"";
 //out.print(buffer);
 response.getWriter().print(buffer);
 %>

请帮我 !!

4

1 回答 1

0

我想这就是你要找的:

success: function(html){
    $("#msg4").hide();
    $("#officers").html(html);
    $("#officers").dropdownchecklist();
}

用这个替换你的成功函数并将它div从你的select.

如果您正在加载 jQuery,为什么不将它用于不仅仅是 ajax 调用?

删除onmouseup,然后试试这个:

$('#design').mouseup(function(){
    $("msg4").show();
    $.ajax({
            url: 'getValues.jsp',
            data: 'design_id='+ $('#design').val(),
            type: 'post',
            success: function(html){
                $("#msg4").hide();
                $("#officers").dropdownchecklist("destroy");
                $("#officers").html(html);
                $("#officers").dropdownchecklist();
            }
           });
});
于 2012-02-29T20:50:43.287 回答