newbiehacker Posted July 28, 2006 Share Posted July 28, 2006 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 |+-----------+------+--------+ Link to comment https://forums.phpfreaks.com/topic/15933-populate-form-with-dropdown-box-selection-please-help/ Share on other sites More sharing options...
Ninjakreborn Posted July 28, 2006 Share Posted July 28, 2006 [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. Link to comment https://forums.phpfreaks.com/topic/15933-populate-form-with-dropdown-box-selection-please-help/#findComment-65470 Share on other sites More sharing options...
newbiehacker Posted July 28, 2006 Author Share Posted July 28, 2006 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? Link to comment https://forums.phpfreaks.com/topic/15933-populate-form-with-dropdown-box-selection-please-help/#findComment-65474 Share on other sites More sharing options...
hostfreak Posted July 29, 2006 Share Posted July 29, 2006 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. Link to comment https://forums.phpfreaks.com/topic/15933-populate-form-with-dropdown-box-selection-please-help/#findComment-65487 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.