Jump to content

Populate form with dropdown box selection PLEASE HELP


newbiehacker

Recommended Posts

Hi I am a newbie programmer and I am stuck with this problem. I need to populate a form (text boxes) when the user selects a value from a dropdown box. here is the code that I am populating the dropdown box with
<?php
$sql = "select extension from role";
$Pass = $db->query($sql);

echo '<tr><td>View Roles :</td><td><select name="role">';
while($Pass->fetchInto($row)){
$id = $row[0];
echo '<option name="role"value='.$id.'>'.$id.'</option>';
}
echo '</select>';
?>
here is the mysql data base that i need to populate the textboxes with the extension field is the dropdown box values. I need it so when a user clicks the dropdown box and chooses a extension it fills the textboxes with everything on that row. Any Help Thanks
+-----------+------+--------+
| extension | dnd  | paging |
+-----------+------+--------+
| default  | off  | on    |
| trial    | off  | on    |
| test      | off  | on    |
| test3    | off  | on    |
+-----------+------+--------+
[code]<?php
      $sql = "select extension from role";
      $Pass = $db->query($sql);
     
      echo '<tr><td>View Roles :</td><td><select name="role">';
      while($Pass->fetchInto($row)){
      $id = $row[0];
        echo '<option name="role"value='.$id.'>'.$id.'</option>';
      }
      echo '</select>';     
?>  [/code]
for one try reformatting the code, see if that helps
[code]<?php
      $sql = "select extension from role";
      $Pass = $db->query($sql);
     
      echo "<tr><td>View Roles :</td><td><select name=\"role\">";
      while($Pass->fetchInto($row)){
      $id = $row[0];
        echo "<option name=\"role\" value=\"{$id}\">{$id}</option>";
      }
      echo "</select>";     
?>  [/code]
if that doesn't work say what is happening, is the value just turning up blank.
Try this:
[code]
<?php
$query = "SELECT extension FROM table ORDER BY";
$result = mysql_query($query);
print "<SELECT name=extension><option>Choose Extension</option>";
while ($row = mysql_fetch_assoc($result))
    {
        echo  "<option value='{$row['extension']}'>{$row['extension]}</option>";
    }
    mysql_close($link);
print "</SELECT>";
?>
[/code]

Make sure to change "table" to the table where the extension is located.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.