title: cascading dropdown with Multiselect using Ajax and JSP
body: <p>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.</p>
  
  <pre><code>&lt;select multiple="multiple" name="RequirementFor" id="RequirementFor" onchange="showState(this.value);"&gt;
  
   &lt;option value="1"&gt;Test1&lt;/option&gt;
      &lt;option value="2"&gt;Test2&lt;/option&gt;
  &lt;option value="3"&gt;Test3&lt;/option&gt;
  &lt;option value="4"&gt;Test4&lt;/option&gt;
  &lt;/select&gt;
  &lt;div id="plat"&gt;&lt;select name="Platform" id="Platform"  multiple="multiple"     onchange='showState2(this.value)'&gt;
  
      &lt;/select&gt;&lt;/div&gt;
  //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   ;
  }
  }
  </code></pre>
  
  <p>below is code from JSP query(apps.jsp) page.</p>
  
  <pre><code>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&gt;0)
  {
  for(int i=0;i&lt;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="&lt;select name='state' multiple='multiple'&gt;&lt;option value='-1'&gt;Select&lt;/option&gt;";
  
  
   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+"&lt;option value='"+rs.getString("FU_ID")+"'&gt;"+rs.getString("FU_NAME")+"&lt;/option&gt;";  
     }  
   buffer=buffer+"&lt;/select&gt;";  
   response.getWriter().println(buffer); 
   stmt.close();
   rs.close();
   con.close();
   }
   catch(Exception e){
       System.out.println(e);
   }
  </code></pre>