SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to send the multiple values selected from list box to ajax

    Hi
    all

    I am using the list box to send the data to server using ajax and getting the response.

    Here is the code

    <script type="text/JavaScript">

    function showUser(str)
    {

    if (str.length==0)
    {
    document.getElementById('txtHint').innerHTML="";
    return;
    }

    var url="/tim/kerproject/phpforms/facultyajax.php";
    url=url+"?q="+str;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById('txtHint').innerHTML=xmlhttp.responseText;
    }
    }
    //xmlhttp.open("GET","ajatest2.php?q="+str,true);
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
    }

    </script>


    <?php

    include("config1.php");
    $result=mysql_query("select batch_id from batch_master");

    echo "<select name='batchid' id='batchid' onchange='showUser(this.value)'>";
    echo "<option value=''>Select </option>";

    while($row=mysql_fetch_array($result))
    {
    $bat=$row['batch_id'];
    echo "<option value='$bat'>$bat";
    }
    echo"</select>";




    echo"<br />";
    echo"<div id='txtHint'>";
    echo"</div>";

    ?>


    In this list box we can select single value and send it to ajax.

    Now I want to select multiple values from the listbox and send it to ajax.

    please help me out

    Thanks

    MD.Samiuddin

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by samiuddin.adse View Post
    In this list box we can select single value and send it to ajax.

    Now I want to select multiple values from the listbox and send it to ajax.
    You would want to use a select box with the multiple attribute enabled, and replace the onchange event with a button's onclick event instead.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,192
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Have a look at the following demo I put together, hopefully it makes sense otherwise let me know and I'll explain what it does.

    http://jsfiddle.net/chrisupjohn/JfqmX/

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by chris.upjohn View Post
    Have a look at the following demo I put together, hopefully it makes sense otherwise let me know and I'll explain what it does.

    http://jsfiddle.net/chrisupjohn/JfqmX/

    Dear Paul

    Thanks a lot for your help. I will check this code and get back to you.

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by samiuddin.adse View Post
    Dear Paul

    Thanks a lot for your help. I will check this code and get back to you.
    You're welcome Chris.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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