View Full Version : Populate text boxes via drop down lists

12-11-2006, 07:54 PM
I have read my threads on these forums regarding this, but for whatever reason I absolutely can not get the code to work for myself. Here is the address that I am attempting it on.

And here is the sample php code:



@mysql_select_db($database) or die( "Unable to select database");
$query= "SELECT * FROM gastable ORDER BY Name ASC";
$result=mysql_query($query)or die( mysql_error());



function fillFields(oSel)
var oForm = oSel.form;
switch (oSel.options[oSel.selectedIndex].value)
case '1':oForm.field1.value=$row[1];oForm.field2.value=$row[2];break;
case '2':oForm.field1.value='blah2';oForm.field2.value='foo2';break;
case '3':oForm.field1.value='blah3';oForm.field2.value='foo3';break;
<select name="T" onchange="fillFields(this)">
<option value="1">item 1</option>
<option value="2">item 2</option>
<option value="3">item 3</option>
<input type="text" name="field1" />
<input type="text" name="field2" />

This code is a frankentstein of code that I found on these forums. basically at this point I don't care what is suggested so long as it works.

I do not know how to get the fancy table code printout, but basically it has the following columns:

ID int
Name text
Address text
Regular decimal(3,2)
Middle decimal(3,2)
Premium decimal(3,2)
Timestamp bigint

My main goal is to create a drop down box that is populated by the station name and address in this format "$Name" - "$Address". Then once the user selects that it will auto populate the name, and address text boxes in the form. If you need any more info please just let me know.