Forum Moderators: coopster

Message Too Old, No Replies

Retaining drop down list box value of a form after posting

dropdown box is populated by database.

         

phlogit

8:48 pm on Jun 11, 2007 (gmt 0)

10+ Year Member



Hi,
I currently have my drop down lists populated by a table from the sql database how can i retain the selected option once the form has been submitted. I know how to do this with textfields but cant figure out the dropdown lists because its being populated by a db.

My code is as follows.

$cat = "<option value=>all</option>";
$cat .= "<option value=$row[id] $catselected>$row[name]</option>";

echo "<tr>\n";
echo "<td class=\"classadd1\"><div class=\"maininputleft\">category</div></td>\n";
echo "<td class=\"classadd2\">\n";
echo "<select name=\"in[catid]\" style=\"width:200px;\" onchange=\"changecat(this.options[this.selectedIndex].value)\">$cat</select>";
echo "</td></tr>\n";

All help greatly appreciated

phparion

12:58 pm on Jun 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



when you populate your dropdown you can place a ternary operator or if condition to check if the value is equal to the already existing value if it is then add word SELECTED otherwise not.