Jump to content


This topic is now archived and is closed to further replies.


Getting Listbox to populate a text field based on selected value

Recommended Posts

Hi All,

I have a list box that is populated directly from an ever growing database feeder table. This works fine,

The feeder table has the followign structure

CustomerID        CustomerName        CustCategory
1                      Airtours                  Tourist Industry
2                      MacDonanlds          Food Industry

The listbox is found on a form, once submitted the main value (CustomerName) from the list box is entered into another database table

What I also need to do is extract the CustCategory of the selected and place this into a variable on the click event of the listbox.

I then want to automatically populate another textfield on the form with this variable to be submitted into the database.

Here is my cod efor the list box.

  $conn = db_connect();
  $query_client = "SELECT * FROM tblClients ORDER BY CustomerName ASC";
  $result_client =  sql_return($query_client);
  $result_client = mysql_query($query_client);
<td width="27%" valign="bottom"> <div align="left">       
  print "<SELECT NAME=CustomerName>";
  print "<OPTION>Please Select....</OPTION>";
          while($client_info = mysql_fetch_array($result_client))
  echo $CustomerID;
  print "<OPTION value='$CustomerID'>$CustomerName</OPTION>";
  print "</SELECT><br><br>";

  $conn = db_connect(); is in an include file and works fine.

Many thanks in advance.


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.