这是我在本网站上的第一个问题,希望我能解释清楚。我确实发现了同样的问题,但主要是在PHP中,我并不理解(例如How to replace url parameter with javascript/jquery?)。在这里我的解释:
我在Javascript中有一个函数(在页面testStudentFile.jsp中):
<script language="javascript">
function onParamChange(){
var thisForm = document.frmParam;
var strBranch = thisForm.reqBranch.value;
var strFaculty = thisForm.reqFaculty.value;
var strCourse = thisForm.reqCourse.value;
location.href ="testStudentFile.jsp?reqBranch="+strBranch+"&reqFaculty="+strFaculty+"&reqCourse="+strCourse;
}
</script>
&#13;
从这里获取值(并在同一页面上发布):
<form name="frmParam" action="testStudentFile.jsp" method="POST">
<tr>
<td width="20%"><strong>Branch:</strong></td>
<td>
<%renderDropDownList2(out, "reqBranch", arrBranch, requestValue.strBranch,"onchange=\"onParamChange()\"");%><%=strBranchDesc%>
</td>
</tr>
<tr>
<td width="20%"><strong>Faculty:</strong></td>
<td>
<%renderDropDownList2(out, "reqFaculty", arrFaculty, requestValue.strFaculty,"onchange=\"onParamChange()\"");%><%=strFacultyDesc%>
</td>
</tr>
<tr align="left">
<td><strong>Course: </strong></td>
<td>
<%renderDropDownList2(out, "reqCourse", arrCourse, requestValue.strCourse,"onchange=\"onParamChange()\"");%><%=strCourseDesc%>
</td>
</tr>
<tr align="left">
<td> </td><td><strong><%out.print(arrStudent.size() + " students");%></strong>
</td>
</tr>
<tr>
<td></td>
<td><input name="reqSearch" class="iform" type="submit" value="Search"></td>
</tr>
</form>
&#13;
从使用sql查询调用数据的方法void中检索数据。查询示例之一: -
<%!
public void populateBranch(JspWriter out, Connection ConnTC, ArrayList arrBranch)throws Exception{
String sqlSelect = " SELECT DISTINCT branch FROM university"+
" WHERE active='Y'"+
" AND branch='PK'"+
" OR branch='ZZ'";
//out.print(sqlSelect);
PreparedStatement stmtSelect = ConnTC.prepareStatement(sqlSelect);
ResultSet rsSelect = stmtSelect.executeQuery();
while(rsSelect.next()){
String strBranch = getValue(rsSelect.getString("fbrncd"));
arrBranch.add(strBranch);
}
rsSelect.close();
stmtSelect.close();
}
%>
&#13;
这是我的问题:
当我选择PK作为分支时,它会自动列出相关的院系和下一个相关课程的下拉列表,但是当我选择ZZ时,从PK分支选择的教师和课程没有重置为默认(空)之前我可以为分校ZZ选择一个教师和一门课程。当分支发生变化时,如何将下拉列表(没有重置按钮)重置为URL参数值中的默认值,如上面的Javascript中所述?
(实施例)
要 - &GT; http://xxx.xxx.xx.x/portal/testApp/request/testStudentFile.jsp?reqBranch=ZZ&reqFaculty=&reqCourse=
温馨的问候&lt; 3,
Eja; - )
答案 0 :(得分:0)
当分支是ZZ时,你想要清晰的strFaculty和strCourse吗? 然后,试试这个
var thisForm = document.frmParam;
var strBranch = thisForm.reqBranch.value;
var strFaculty = strBranch == 'ZZ' ? '' : thisForm.reqFaculty.value;
var strCourse = strBranch == 'ZZ' ? '' : thisForm.reqCourse.value;
location.href = ....
我希望这对你有用。感谢。
答案 1 :(得分:0)
Here is my solution在其他更改时重置下拉列表。 基于this thread和this one。
只需在一个下拉列表中更改值时调用函数:
onchange="reset()"
在复位功能中,选择要更改索引的元素并将其设置为0:
var element = document.getElementById('id');
element.value = 0; // first value, an empty option in this example