Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2011
    Posts
    101
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Post 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"); 

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,182
    Thanks
    23
    Thanked 603 Times in 602 Posts
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •