I am sending multiselect dropdown values to a JSP PAGE. Below is the AJAX code that send the multiselect values. The JSP PAge includes SQL query to read from database and show its values in another dropdown. Below code only display cascading dropdown values based on on select and not multiselect. It appears that only one value is sent to apps.jsp and not all values. I tried few changes and it didn’t work. Below is the best working code available with me. Any help to get second dropdown display values based on multiselect from first dropdown? Single dropdown works fine with below code. Thank you.
<select multiple="multiple" name="RequirementFor" id="RequirementFor" onchange="showState(this.value);">
<option value="1">Test1</option>
<option value="2">Test2</option>
<option value="3">Test3</option>
<option value="4">Test4</option>
</select>
<div id="plat"><select name="Platform" id="Platform" multiple="multiple" onchange='showState2(this.value)'>
</select></div>
//AJAX Code
var xmlHttp ;
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="apps.jsp";
url +="?value=" +str;
xmlHttp.onreadystatechange = stateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function stateChange(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("plat").innerHTML=xmlHttp.responseText ;
}
}
below is code from JSP query(apps.jsp) page.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost", "username", "password");
Statement stmt;
ResultSet rs;
String[] funID= request.getParameterValues("value");
String conCat = "";
try{
if(funID.length>0)
{
for(int i=0;i<funID.length; i++)
{
conCat = funID[i] +" "+ "OR" + " "+ "FU_DEPARTMENT_ID= " + conCat;
}
conCat = conCat.substring(0, conCat.length() - 22);
}
}
catch(Exception e)
{out.println(e);}
String buffer="<select name='state' multiple='multiple'><option value='-1'>Select</option>";
try
{
String sqlSelect1="Select FU_ID, FU_NAME from UNIT where FU_DEPARTMENT_ID ="+conCat+" ORDER BY FU_NAME ASC";
stmt = con.createStatement();
rs = stmt.executeQuery(sqlSelect1);
while(rs.next()){
buffer=buffer+"<option value='"+rs.getString("FU_ID")+"'>"+rs.getString("FU_NAME")+"</option>";
}
buffer=buffer+"</select>";
response.getWriter().println(buffer);
stmt.close();
rs.close();
con.close();
}
catch(Exception e){
System.out.println(e);
}
I think you should change the way you get multi-values. Some thing likes this: