Populating an HTML ListBox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CraigMuckleston
    New Member
    • Mar 2007
    • 15

    #1

    Populating an HTML ListBox

    I have the following php code that retrieves a list of items. I want to populate a listbox with the XMLHttpRequestO bject, but I am getting 1 long string instead of each item on a line. How can I populate the listbox correctly:

    [code=php]
    <?php

    $dsn="Driver={S QL Server};Server= myserver;Databa se=mydb;";
    $username="user ";
    $password="pwd" ;

    $sqlconnect=odb c_connect($dsn, $username,$pass word);
    $sqlquery="SELE CT item, description
    FROM db..tbl1 (nolock)
    WHERE item LIKE '" . $_GET['q'] . "%'
    OR description LIKE '%" . $_GET['q'] . "%'
    AND item_status = 'A'";
    $process=odbc_e xec($sqlconnect , $sqlquery);

    while(odbc_fetc h_row($process) )
    {
    $item = odbc_result($pr ocess,"item");
    $description = odbc_result($pr ocess,"descript ion");
    $supdet = $item.' - '.$description;
    echo $supdet;
    }
    odbc_close($sql connect);

    ?>
    [/code]

    My javascript code to handle the income responseText is:

    [code=javascript]
    function getList(dataSou rce)
    {
    xmlHttp=new ActiveXObject(" Microsoft.XMLHT TP");
    xmlHttp.onready statechange=fun ction()
    {
    if(xmlHttp.read yState==4)
    {
    document.getEle mentById("autoL istResults").ad d(new Option (xmlHttp.respon seText, xmlHttp.respons eText));
    document.getEle mentById("autoL istResults").st yle.visibility = "visible";
    }
    }
    xmlHttp.open("G ET","server2.ph p?q=" + dataSource, true);
    xmlHttp.send(nu ll);
    }
    [/code]

    < Please use [code] tags when posting code! -Atli >
    Last edited by Atli; Jun 29 '07, 06:06 PM. Reason: Added code tags.
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    I'm still playing around with AJAX myself, but I believe that the easiest way to split up all of those items is to have them formatted as an XML file, each an <item>.

    Comment

    Working...