[noob] populate textbox from dropdown

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
GuitarCoder
Forum Newbie
Posts: 4
Joined: Tue Aug 12, 2008 5:27 pm

[noob] populate textbox from dropdown

Post by GuitarCoder »

here's the scenario... it is simple but im a noob on this. ..

when you select a value from a dynamic dropdown, how can i get other values from the same row of that database?

ex:

dropdown: Home / School / Office /

When they select Home, i want to get the values for address, city, zip and show them on a textboxes (or a hidden field)?


Here's my code:

Code: Select all

function generate_department($conn){
$departments="";
 
$query = "SELECT DISTINCT address, city, zip, dept FROM tblDepartment";
 
$result = odbc_exec($conn,$query);
 
    while ($return = odbc_fetch_array($result)){
        $departments.="<option value='".htmlentities($return["dept"])."'>".$return[dept]."</option>";
    }
    return $departments;
 
}

here's my dropdown:

Code: Select all

<select size="1" name="Department">
          <option value="">Select One</option>
          <?php echo generate_department($db); ?>
</select>

dropdown works fine, now i want to see my address, city, and zip and place them on a separte textboxes (or a hidden field)

...


my goal is to get all these values then write them on a separate database


any help would be appreciated... thanks! :banghead:
Post Reply