Current location: Hot Scripts Forums » Programming Languages » PHP » Dropdown lists determines textarea content


Dropdown lists determines textarea content

Reply
  #1 (permalink)  
Old 02-07-04, 01:15 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Dropdown lists determines textarea content

I hope this is an easy answer for someone. I have customer info, including names and addresses, stored in a database. The field names are name, address, city, state, zip.

I have a form for a program I am developing to enter customer orders. One part of the form has a dropdown list populated from the database which brings up the saved customer names ( for example, Customer 1, Customer 2, etc., and this works fine ), and looks like this...

Sold To:<?php
include("customer_list.php"); ?>

Following that is a textarea for a shipping address, which is pretty basic...

Ship to:<br>
<textarea name=ship_to cols=30 rows=4></textarea>

I'm wondering if its possible so that when I select a customer name from the dropdown, the "Ship To" textarea will automatically display the selected customers' address in the "Ship to" textarea so that it doesn't have to be manually typed in?

Customer_list.php ( if it helps any )...





php: include("dbinfo.inc.php");
$conn = mysql_connect("$location","$username","$password");

if (!
$conn) die ("Could not connect MySQL");
mysql_select_db($database,$conn) or die ("Could not open database");
$sql="SELECT * FROM customers";
$result=mysql_query($sql);

$options="";

while (
$row=mysql_fetch_array($result)) {
$name=$row["name"];
$options.="<OPTION VALUE=\"$name\">".$name;
}
?>
<SELECT NAME=name>
<OPTION VALUE=0>Select Customer
<?=$options?>
</SELECT>

Thnx....
Reply With Quote
  #2 (permalink)  
Old 02-08-04, 09:46 PM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,

Just like the one I replied to before this, you can use a combo of Javascript and PHP. OnChange is a popular event to do this. Pass the parameter according to the selection made, and retrieve the information ("Ship to:") and display it. Alternatively, you can choose to have all the Ship To info loaded onto JavaScript and switch it after the page is loaded, depending on which combobox item is selected. That way, you don't have to load the page again when the selection is made. Whichever suits your needs better, I guess.
__________________
Blavv =|
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 08:44 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.