
i have two list boxes first list box values from database and i want to assign selected options to the second list box using jsp is it possible to do this in jsp?

1)select.jsp:
<%@page import="java.sql.*"%>
<html>
<head>
<script type="text/javascript">
var xmlHttp;
function showState(str){
if (typeof XMLHttpRequest != "undefined"){
xmlHttp= new XMLHttpRequest();
}
else if (window.ActiveXObject){
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlHttp==null){
alert ("Browser does not support XMLHTTP Request")
return
}
var url="select2.jsp"
url=url+"?fooditem="+str
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
document.getElementById("item").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject(){
var xmlHttp=null;
try{
xmlHttp=new XMLHttpRequest();
}
catch (e) {
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
</head>
<body>
<form name="employee">
<br><br>
<b>Select Food Item</b>
<select name="name" onchange="showState(this.value);">
<option value="-1">Select</option>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from items");
while(rs.next()){
%>
<option value="<%=rs.getString("item")%>"><%=rs.getString("item")%></option>
<%
}
%>
</select>
<div id='item'>
<b>Select Item          </b>
<select name='item' >
<option value='-1'></option>
</select>
</div>
</form>
</body>
</html>
2)select2.jsp:
<%@page language="java" import ="java.sql.*" %>
<%
String fi=request.getParameter("fooditem");
String buffer="<b>Select Item          </b> <select>";
buffer=buffer+"<option value='"+fi+"'>"+fi+"</option>";
buffer=buffer+"</select>";
response.getWriter().println(buffer);
%>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.