我正在尝试从success.jsp自动重定向到feedbackform.jsp,当组合框值更改并将所选值发送到feedbackform.jsp时。但我很困惑,没有得到如何做到这一点。到目前为止我做了什么 -
此代码在success.jsp
上<script>
function myFunction() {
var x = document.getElementById("mySelect").value;
document.getElementById("demo").innerHTML = "You selected: " + x;
}
</script>
</head>
<body>
<h1><center>Feed Back System</center></h1>
<center>
<%
if ((session.getAttribute("userid") == null) || (session.getAttribute("userid") == "")) {
%>
<font size='4' color='red'>You are not logged in</font><br/>
<a href="index.jsp">Please Login</a>
<%} else {
%>
<p class="member">Welcome <%=session.getAttribute("userid")%>, you are from semester <%=session.getAttribute("category")%></p>
<a href='logout.jsp'>Log out</a>
<%
}
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/feedback","root", "");
Statement st = con.createStatement();
ResultSet rs;
rs = st.executeQuery("select * from faculty");
%>
<form method="post" name="myform" action="feedbackform.jsp">
<table width="480" border="0">
<tr>
<td colspan="3"><font color="#00FFCC" size="4">Tip :- “Select 1 for excellent 2 for better 3 for good 4 for poor”</font></td>
</tr>
<tr><td> </td></tr>
<tr>
<td width="151" class="member">Select Faculty</td>
<td width="264" colspan="2"><select id="mySelect" onchange="myFunction()">
<% while(rs.next()){ %>
<option><%= rs.getString(2)%></option>
<% } %>
</select>
</td>
</tr>
</table>
</form>
<p id="demo"></p>
</center>
现在在这里,我被困住了如何在下拉时重定向&#34; mySelect&#34;价值变化。 请指导我。 感谢所有人提前回复。
答案 0 :(得分:0)
在java脚本中更改myFunction()代码
<script>
function myFunction() {
var x = document.getElementById("mySelect").value;
var y = "your value";
document.getElementById("demo").innerHTML = "You selected: " + x;
window.location = "http://www.yoururl.com"; //redirect normally on changes
/* you can also check select value with condition and redirect like this
if (X.toLowerCase() === y.toLowerCase())
{
window.location = "http://www.yoururl.com";
}
*/
}
</script>