Forums

PHP

This topic is locked

Dynamic List Populating Text Field

Posted 15 Feb 2007 21:23:43
1
has voted
15 Feb 2007 21:23:43 Nathan Kuhl posted:
I have a MySQL table with two columns: Name and Email

What I need to do is in my PHP page, insert a dynamic list box populated with all of the names in the table. I have that working.

Next, when I click on any of the names in that list box, I want the corresponding email address to show up in a seperate text field. This is something that shouldn't be difficult but I've been beating my head against the wall trying to figure it out. When a name is selected, the text field displays that person's corresponding email.

Can anyone help me out? I'm using dreamweaver mx 2004 and a PHP page.

Thanks.

Replies

Replied 27 Feb 2007 13:43:38
27 Feb 2007 13:43:38 Roddy Dairion replied:
The Value in the list box should either contain that person's name or the id for this person's details. Then using a bit of javascript or ajax you can retrieve it.
here's a simple way of doing here i've using static for my dropdown but u can replace this by using dynamic data from ur database.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" language="javascript">
function populate()
{
if (document.form1.select.value != ""
{
document.form1.textfield.value = document.form1.select.value;
}
}
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
<p>
<select name="select" onchange="populate();">
<option value="Roddy Dairion">Roddy</option>
<option value="Roders Dairion">Roddy1</option>
<option value="Rodstar Dairion">Roddy2</option>
<option value="Mr Dairion">Roddy3</option>
</select>
</p>
<p>
<input type="text" name="textfield" />
</p>
</form>
</body>
</html>

Reply to this topic