请我需要您的帮助,了解如何在 Jsp 中从数据库中生成下拉值的依赖文本框。下面的代码可以很好地处理一个文本框。但我不知道如何制作多个依赖的文本框。所以请帮助我。
谢谢。
tender.jsp:
<%
Connection conn = null;
Statement st = null;
ResultSet rs = null;*
conn = JDBCConnectionUtil.getConnection();
if(conn != null)
{
try
{
String woodSQL = "select fsa_wood_type_master_wood_type, fsa_wood_type_master_wood_weight,fsa_wood_type_master_wood_length,fsa_wood_type_master_wood_width,fsa_wood_type_master_wood_standard_rate from fsa_wood_type_master";
st = conn.createStatement();
rs = st.executeQuery(woodSQL);
}
catch(SQLException e)
{
e.printStackTrace();
}
}
%>
<td>
<select id="woodType" onchange="populateWoodId();">
<%while(rs.next()){ %>
<option value="<%=rs.getString(1) %>"><%=rs.getString(2) %></option>
<%} %>
</select>
<input id="woodHeight" type="text" value="" />
</td>
}
JavaScrip:
function populateWoodId(){
var selectBox = document.getElementById('woodType');
/* selected value of dropdown */
var woodHeight = selectBox.options[selectBox.selectedIndex].value;
/* selected value set to input field */
document.getElementById('woodHeight').value = woodHeight;
}
最佳答案
像这样更改选项标记行:
<option value='<%=rs.getString(1)+"#"+rs.getString(2)+"#"+rs.getString(3)+"#"+rs.getString(4)+"#"+rs.getString(5) %>'><%=rs.getString(2) %></option>
并在你的 JavaScript 中这样做:
function populateWoodId(){
var selectBox = document.getElementById('woodType');
/* selected value of dropdown */
var woodProp = selectBox.options[selectBox.selectedIndex].value;
/* selected value set to input field */
var splitVal=woodProp.split("#",5);
document.getElementById('woodHeight').value = splitVal[0];
document.getElementById('woodHeight1').value = splitVal[1];
document.getElementById('woodHeight2').value = splitVal[2];
document.getElementById('woodHeight3').value = splitVal[3];
document.getElementById('woodHeight4').value = splitVal[4]; //five different textboxes
}
关于java - 如何在jsp中从数据库中的下拉值上创建多个依赖的TextBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29179967/