#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    5
    Rep Power
    0

    Post Sending array of 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 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.

    PHP 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"urltrue);
    xmlHttp.send(null);
    }

    function 
    stateChange(){   
    if (
    xmlHttp.readyState==|| xmlHttp.readyState=="complete"){   
    document.getElementById("plat").innerHTML=xmlHttp.responseText   ;
    }

  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2009
    Location
    Jakarta, Indonesia.
    Posts
    200
    Rep Power
    31
    I don't know how your JSP handles the query, but maybe it could use something from this example:
    Code:
    <script>
    function showState(me){
    	var values = ''; //populate selected options
    	for (var i=0; i<me.options.length; i++)
    		if (me.options[i].selected) values += me.options[i].value + ',';
    	document.getElementById('report').value = values; //report
    }
    </script>
    
    <select multiple="multiple" onchange="showState(this);">
    	<option value="1">Test1</option>
    	<option value="2">Test2</option>
    	<option value="3">Test3</option>
    	<option value="4">Test4</option>
    </select> 
    
    <input type="text" id="report">

    Comments on this post

    • Winters agrees : Teaches me for leaving the thread open for an hour without refreshing.
    • messimagic agrees
  4. #3
  5. No Profile Picture
    Super Moderator
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,008
    Rep Power
    2791
    Already answered.
    Last edited by Winters; November 6th, 2012 at 04:06 AM. Reason: Already answered.
    [PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [ANSI C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

    W3Fools - A W3Schools Intervention.

IMN logo majestic logo threadwatch logo seochat tools logo