Dynamic Dropdown to fill Text Boxes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
chopper_pc
Forum Newbie
Posts: 15
Joined: Fri May 30, 2008 10:55 pm

Dynamic Dropdown to fill Text Boxes

Post by chopper_pc »

Here's what i'm tring to do:
I want users to be able to pulldown a drop down box that will pull a clients name, address...... from a profile database that is already working.
What I want is when they choose the dropdown to have it fill in text fields that they can edit and resubmit. from what I gather this is something that will probably require JAVA. I've messed around and put together the following that works as far as creating the "dynamic" drop down and the JAVA to fill in the first text box. But here I am stuck...
Any ideas on how this could be done?
Here's the code that is working to fill in the dropdown which is filling in the first text box just dandy:

Code: Select all

<head>
<Script Language="JavaScript">
function fillText()
{
document.testForm.DetailText.value=document.testForm.OperationDropDown.value;
}
</Script>
</head>
<body>
<?php
[color=#FF0000]--------ALL SQL CONNECTION OMMITED--------------[/color]
$sql="SELECT * FROM profile ORDER BY name";
$result=mysql_query($sql);
 
$options="";
 
while ($row=mysql_fetch_array($result)) {
 
    $id=$row["id"];
    $name=$row["name"];
    $options.="<OPTION VALUE=\"$name\">".$name;
}
?>
<form name="testForm" id="testForm" action="">
Make Selection<br><br>
<select name="OperationDropDown" onChange="fillText()">
<option value="" selected="true">New Shipper</option>
<option <?=$options?></option>
</select><br>
<input type="text" name="DetailText" id="DetailText" size="10">
</form>
<form action="proc_bol.php" method="post">
<b>
</body></html>
mainegate
Forum Newbie
Posts: 14
Joined: Sat Nov 29, 2008 5:49 pm

Re: Dynamic Dropdown to fill Text Boxes

Post by mainegate »

here is the code to populate your dropdown from the db.

Code: Select all

 
<?php 
include("con.php");
?>
<select name="usernameDropdown" onchange="fillText()">
<option value="">--- Select ---</option>
<?
 
$list=mysql_query("SELECT username FROM login");
 
// Show records by while loop.
while($row_list=mysql_fetch_assoc($list)){
?>
<option value="<? echo $row_list['username']; ?>" <? if($row_list['username']==$select){ echo "selected"; } ?>><? echo $row_list['username']; ?></option>
<?
// End while loop.
}
?>
</select>
Post Reply