473,382 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Populating an HTML ListBox

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

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $dsn="Driver={SQL Server};Server=myserver;Database=mydb;";
  4. $username="user";
  5. $password="pwd";
  6.  
  7. $sqlconnect=odbc_connect($dsn,$username,$password);
  8. $sqlquery="SELECT item, description
  9.            FROM db..tbl1 (nolock)
  10.            WHERE item LIKE '" . $_GET['q'] . "%'
  11.            OR description LIKE '%" . $_GET['q'] . "%'
  12.            AND item_status = 'A'";
  13. $process=odbc_exec($sqlconnect, $sqlquery);
  14.  
  15. while(odbc_fetch_row($process)) 
  16.     $item = odbc_result($process,"item");
  17.     $description = odbc_result($process,"description");
  18.     $supdet = $item.' - '.$description;
  19.                 echo $supdet;
  20. }
  21. odbc_close($sqlconnect);
  22.  
  23. ?>
  24.  
My javascript code to handle the income responseText is:

Expand|Select|Wrap|Line Numbers
  1. function getList(dataSource)
  2. {  
  3.   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");  
  4.   xmlHttp.onreadystatechange=function()
  5.   {
  6.     if(xmlHttp.readyState==4)
  7.       {
  8.      document.getElementById("autoListResults").add(new Option      (xmlHttp.responseText, xmlHttp.responseText));
  9.      document.getElementById("autoListResults").style.visibility = "visible";
  10.       }
  11.   }
  12. xmlHttp.open("GET","server2.php?q=" + dataSource, true);
  13. xmlHttp.send(null);
  14. }
  15.  
< Please use [code] tags when posting code! -Atli >
Jun 29 '07 #1
1 2079
kovik
1,044 Expert 1GB
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>.
Jun 29 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: cloverme | last post by:
Hi, I need help populating a listbox from a database on a webform. I created a an access database with a table, fields and data. Then I created a WebForm in vb.net and added a DropDownList...
0
by: Bill Brinkworth | last post by:
I want the user to type in part of a word, and I want to return all words from an Access word table that contains specified letters. If they were to type "fe??", it should return all words in the...
6
by: Deano | last post by:
I needed to have a listbox populated by locations which are stored in tblLocations. However I wanted an "All locations" entry to be at the top of the listbox. This is not in the tblLocations. The...
2
by: collie | last post by:
Hi, I have 2 listboxes. The first gets populated from the db as soon as the page loads. The second listbox get populated based on the user's selection from the first listbox. However,...
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
6
by: P K | last post by:
I have a listbox which I am populating on the client (it contains a list of dates selected from calender). The listbox is a server control. When I get to the server after postback by selecting an...
8
by: jack-b | last post by:
Hi, I have a list box which displays countries names and a second listbox which displays their cites (based on the selection made in ListBox 1) If the user selects USA i want to display cities...
2
by: NvrBst | last post by:
I populate a ListBox with a LogFile that has about (~1000 lines). The ListBox's datasource is a BindingList<string>. Whenever I add the elements, with the datasource set, it takes about 2 mins. ...
1
by: dkohel | last post by:
I have 2 list boxes on my form. I am trying to populate listbox B with the selection from listbox A. I have set multi-select in both boxes to Extended... The user will select the items from...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.