View Full Version : Javascript and mysql

02-03-2005, 01:03 PM
I'm not very confortable with javascript and need some help. :rolleyes:
I have the following scipt on my php page:


$resultado=mysql_query("select * FROM associated ORDER BY enterprise asc") or die("Erro ao listar tabela");
echo ("<table width=\"95%\" border=\"0\">");
echo "<tr>";
echo "<td class=\"texto\"><form name=\"associated\" method=\"post\" action=\"\" ><select name=\"list\"> <option value=\"\" selected>Associated List</option>";
while ($registo=mysql_fetch_row($resultado))
echo "<option value=\"$registo[1]\">$registo[1]</option>";
echo "</select><br>";
echo "<input type=\"text\" name=\"adress_field\"><br>";
echo "<input type=\"text\" name=\"sector_field\"><br>";
echo "<input type=\"submit\" name=\"Submit2\" value=\"Submit\">";
echo "</form></td>";
echo "</tr>";
echo ("</table>");



Well, I know this is a javascript forum but what I need is a javascript.
As you may see, the listbox has dynamic content from a Mysql table with the "id, enterprise, adress, sector" fields.
I now wanted to chose an enterprise from the list box and the two text fields below would be automatic filled with the correspondent data from the mysql table.
Hope this is understandable...
Thanks in advance!

Willy Duitt
02-06-2005, 06:20 PM
Unfortunetely you did not provide the necassary information as to how the data coming from the database is displayed in the option values... But assuming the it is comma delimited and the address is first while the sector is second, the solution would be something like so...

echo "<td class=\"texto\"><form name=\"associated\" method=\"post\" action=\"\" >
<select name=\"list\" onchange="this.form.adress_field.value='this.value.split(',')[0];this.form.sector_field.value='this.value.split(',')[1]">
<option value=\"\" selected>Associated List</option>";