Java 根据第一个选择框的选择填充第二个选择框
有两个下拉列表,第二个下拉列表将基于第一个选择框填充。 它们都将从数据库中填充。我已经填充了第一个选择框,也填充了第二个选择框,但是所有的值都是一个值。 第一个选择框:Java 根据第一个选择框的选择填充第二个选择框,java,jquery,ajax,jsp,Java,Jquery,Ajax,Jsp,有两个下拉列表,第二个下拉列表将基于第一个选择框填充。 它们都将从数据库中填充。我已经填充了第一个选择框,也填充了第二个选择框,但是所有的值都是一个值。 第一个选择框: <select id="country_obj" name="custCountry" class="field_size_e" onchange="populateSecValues(this);"> <option value="">-select-</option> &l
<select id="country_obj" name="custCountry" class="field_size_e" onchange="populateSecValues(this);">
<option value="">-select-</option>
<%
Iterator contryIter = countries.iterator();
Lookup lookup = null;
while(contryIter.hasNext()) {
lookup = (Lookup)contryIter.next();
out.print("<option value='"+lookup.getValue()+"'");
out.print(">");
out.print(lookup.getLabel());
out.println("</option>");
}
%>
</select>
更改时的功能:
function populateSecValues(obj) {
alert("enter the function");
var country = obj.value;
$.get('/maintenance/timeZoneFinder.jsp?country='+country, function(responseData) {
$("#zones").html(responseData);
});
}
timeZoneFinder.jsp
<%
ResultSet rset = null;
Connection conn = null;
Statement stmt = null;
String SQL_COMMAND = "";
try {
conn = ConnectionManager.getConnection();
stmt = conn.createStatement();
String country = request.getParameter("country");
System.out.println("country========>"+country);
SQL_COMMAND="select a.full_name from org_base.time_zone a where a.country_code='"+country+"'";
rset = stmt.executeQuery(SQL_COMMAND);
ResultSetMetaData meta = rset.getMetaData();
int col = meta.getColumnCount();
while(rset.next()){
out.print("<option value='"+rset.getString(1)+"' >'"+rset.getString(1)+"'</option>");
}
} catch (Exception e) {
e.printStackTrace();
}
finally {
if (rset != null) rset.close();
if (stmt != null) stmt.close();
if (conn != null) conn.close();
}
%>
第二个选择框html
<select>
<option value="" id="zones" class="field_size_e">-<%=bundle.getString("common.select") %>-</option>
</select>
使用like
编辑:你们还在迭代部分加了一些额外的引号。像这样更新它
while(rset.next()){
out.print("<option value='' >-select time zone--</option>");
out.print("<option value='" + rset.getString(1) + "' >" + rset.getString(1) + "</option>");
}
}所有值都作为一个值出现,这是什么意思?有截图吗?@HüseyinBABAL我执行的查询从org_base.time_zone a中选择一个.full_名称,其中a.country_code='+country+'有几个值您没有得到它,我希望这些值在下拉列表中显示为不同的选项第一个下拉列表针对的是我使用另一个表的国家,第二个下拉列表针对您当前的实施使用不同的表,您只得到一个选项?我得到所有值,但作为一个字符串,所有值都显示在第二个下拉列表中,但作为一个字符串,您能告诉我响应文本吗?out上有错误。请打印“+rset.getString1+”
while(rset.next()){
out.print("<option value='' >-select time zone--</option>");
out.print("<option value='" + rset.getString(1) + "' >" + rset.getString(1) + "</option>");
}
<select id="select"></select>
<button id="click">Populate</button>
$(document).ready(function(){
$("#click").on('click', function() {
var html = '<option value="val1">Val-1</option><option value="val12">Val-12</option>';
$("#select").append(html);
});
});
<select id="zones">
<option value="" class="field_size_e">-<%=bundle.getString("common.select") %>-</option>
</select>
$.get('/maintenance/timeZoneFinder.jsp?country='+country, function(responseData) {
$("#zones").html(responseData);
alert("Please select time zone");
$("#zones:first").focus();
});