weixin_33743880 2015-03-30 11:00 采纳率: 0%
浏览 41

JSP中的动态列表框

I have two listboxes on my JSP page. By default the first listbox is filled with database data, When the user selects an item in the 1st listbox, the second will filled accordingly with database data using Ajax. I am new to JSP. I need your help.

I used the below JavaScript code to retrieve the selected value in first listbox.

<script type="text/javascript" > 
  $(document).ready(function(){ 
    $("#rt_select").click(function() { 
      var option = $('#lstsprintid').val(); 
      alert(option); 
      return option; 
    }); 
  }); 
</script>

I am unable to use the value returned from JavaScript in my JSP page. Below is my multiple select listbox where data is coming from db.

<p>Select Name :
<select size="3"  id="lstsprintid" multiple="multiple">
<%
while(rs.next())
{
 String name = rs.getString("s_name"); 

 %>
<option value="<%=name %>"><%=name %></option>
<%
}
%>
</select>           

Which JavaScript code shall I use to get the list of values selected in the above listbox.

 <%
 String s1 = request.getParameter("txt_test");
 out.println(s1);
 Statement st1= con.createStatement();
ResultSet rs1=st1.executeQuery("Select sprint_id from sprint where              sprint_name in ("+ s1 +")");
 %>
  • 写回答

1条回答 默认 最新

  • weixin_33716154 2015-03-31 08:56
    关注

    Use the onchange event with the first list and .selectedIndex to get its selected value:

    <script type="text/javascript" > 
       $("#lstsprintid").onchange(function() { 
          var option = $('#lstsprintid').selectedIndex; 
          alert(option); 
          return option;
          // and the use this value to fill the second list
       });  
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程