CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Ajax and Design (http://www.codingforums.com/forumdisplay.php?f=55)
-   -   sending Multiselect values using ajax (http://www.codingforums.com/showthread.php?t=281108)

naveendk.55 11-06-2012 03:22 AM

sending Multiselect values using ajax
 
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.


Code:


<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  ;
}
}

I am using below JSP code to read arrary of values:

PHP Code:

String[] funID=  request.getParameterValues("value"); 


sunfighter 11-06-2012 02:31 PM

Your HTML and ajax call is working fine. The problem is with your java code and how the HTML treats it. I don't know java, but:

in the HTML your putting the return into the div not the dropdown!
I would write out the entire code for the dropdown in the server side file and send the whole thing (The options and selects) back down the line.


All times are GMT +1. The time now is 04:06 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.