我有以下代码,在下拉列表中显示数据库中的值列表。该查询还选择Jt_JOB_Description。我想根据在Text Area中选择的JT_JOB_TITLE显示Jt_JOB_Description。帮助PLZ。
<select name="jTitle" id="jTitle" style="background-color: #D8D8D8">
<%
Statement stt = conn.createStatement();
ResultSet rstt = stt.executeQuery("SELECT JT_JOB_TITLE, JT_JOB_DESCRIPTION FROM uap.dbo.UAP_JOB_TITLE ORDER BY JT_JOB_TITLE");
while (rstt.next()) {
%>
<option value="<%=rstt.getString("JT_JOB_TITLE")%>"> <%=rstt.getString("JT_JOB_TITLE")%>
</option>
<%
}
stt.close();
rstt.close();
%>
</select>
<textarea class="styled" rows="5" cols="12" name="jDesc" id="jDesc" ></textarea>
答案 0 :(得分:1)
修改您的代码,如下所示
<select name="jTitle" id="jTitle" style="background-color: #D8D8D8" onchange="setText(this)">
<%
String str="";
Statement stt = conn.createStatement();
ResultSet rstt = stt.executeQuery("SELECT JT_JOB_TITLE, JT_JOB_DESCRIPTION FROM uap.dbo.UAP_JOB_TITLE ORDER BY JT_JOB_TITLE");
while (rstt.next()) {
str+=rstt.getString(1)+"@"+rstt.getString(2)+"#";
%>
<option value="<%=rstt.getString("JT_JOB_TITLE")%>"><%=rstt.getString("JT_JOB_TITLE")%>
</option>
<%
}
stt.close();
rstt.close();
%>
</select>
<input type="hidden" name="txtHidStr" id="txtHidStr" value="<%=str %>" />
<textarea class="styled" rows="5" cols="12" name="jDesc" id="jDesc" ></textarea>
并编写以下javascript函数
function setText(element){
var arr_main=document.getElementById("txtHidStr").value.split("#");
for(i=0;i<arr_main.length;i++)
{
arr_val=arr_main[i].split("@");
if(arr_val[0]==element.value)
{
document.getElementById("jDesc").innerHTML=arr_val[1];
break;
}
}
}