Hi, I've been curious about this for ages but how do you go about ensuring your select list has the correct value marked as selected when updating a forum.
Say for example I have made a form with a month field on it as a select list. The user selects the month, saves the document (form) to mysql. Later that day they then decide to edit the data. When they go into the document (form) the values have obviously been prepopulated from the db including the month being marked as SELECTED (ie the corresponding value stored in the db).
This might be the simplest question answer known to man I dont know, but I've written 3 complex bits of code to resolve it. One of which I'm 50% happy with, the other 2 I wanna burn.
Any ideas?
ps hi all btw joined today, been reading for hours, great site.
Dropdowns, selected and editing documents
Moderator: General Moderators
- ambivalent
- Forum Contributor
- Posts: 173
- Joined: Thu Apr 14, 2005 8:58 pm
- Location: Toronto, ON
Compare the month returned by the DB to the select list, act on the results:
Code: Select all
if($monthToSelect == $monthPrePopulated)
{
echo "<option value=\"$monthToSelect\" selected=\"selected\">$monthToSelect</option>\n";
}
else
{
echo "<option value=\"$monthToSelect\">$monthToSelect</option>\n";
}