CincoPistolero Posted March 12, 2008 Share Posted March 12, 2008 I have a form that dynamically fills dropdowns in the form. When adding to the db using the form, all is ok. but I have another page that allows data to be modified. this page also has the dynamic dropdowns. I want to know how to have the modify form autopick the value in the Select dropdown that is already in the db. And make sure that when I click the modify button, that it maintains what is already selected without having to reselect it. Below is my current code which lists at the top of the drop down what is in db, but when I click modify button it deletes the current entry. thanks in advance <td width="150">Access Level:</td> <td width="330"> <?php /* Users Information Query */ $queryaccess = " SELECT * FROM accessLevel ORDER BY value"; $resultaccess = mysql_query($queryaccess) or die ("Error in query: $queryaccess. " . mysql_error()); ?> <select name="accessLevel"> <option selected><?php if ($usersrow["accessLevel"] == 1) { echo 'User'; } else { echo 'Administrator'; }?></option><?php while ( $rowaccess= mysql_fetch_array($resultaccess)){extract($rowaccess); echo " <option value='$value'>$name</option>" ;}?> </select> </td> Link to comment https://forums.phpfreaks.com/topic/95834-html-select-dropdowns/ Share on other sites More sharing options...
soycharliente Posted March 12, 2008 Share Posted March 12, 2008 You'll need selected="selected" inside one of the options and it will default to that option. HTML attributes should always use double quotes BTW. Just escape it. echo "<option value=\"$value\">$name</option>"; Or concat the variable in if you're uncomfortable with escaping. echo '<option value="'.$value.'">'.$name.'</option>'; Link to comment https://forums.phpfreaks.com/topic/95834-html-select-dropdowns/#findComment-490608 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.