Jump to content


Photo

Populate form with dropdown box selection PLEASE HELP


  • Please log in to reply
3 replies to this topic

#1 newbiehacker

newbiehacker
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 28 July 2006 - 09:53 PM

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    |
+-----------+------+--------+


#2 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 10:32 PM

<?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>';      
?> 

for one try reformatting the code, see if that helps
<?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>";      
?> 

if that doesn't work say what is happening, is the value just turning up blank.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#3 newbiehacker

newbiehacker
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 28 July 2006 - 11:00 PM

I need to be a little clearer Im not sure how to even fill the text boxes with the data. How do you enter the sql into the textboxes?

#4 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 29 July 2006 - 02:44 AM

Try this:
<?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>";
?>

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users