Page 1 of 1

Dynamic Dropdown to fill Text Boxes

Posted: Tue Dec 02, 2008 6:53 pm
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>

Re: Dynamic Dropdown to fill Text Boxes

Posted: Tue Dec 02, 2008 11:57 pm
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>