Forum Moderators: coopster
Hope I haven't lost you yet (I tend to do that)
Now this is an example of one of the select statements.
option 1
option 2
option 3
option 4
Now if option 3 is what is entered into the database I would like that to be showing when the user clicks the page. So the option in the database I would like to be the default option.
Thanks for any help.
Cheers
Just bring your variables into the page as you normally would and use the code in that ^ works a treat.
W.
all I am trying to do is say 18 is the level. I want it selected when the page is brought up. So.
<option value='17'>17
<option value='18' SELECTED>18
<option value='19'>19
<option value='20'>20
Thats all I need, but dynamic and on 3 other select statements.
Any easier way?
Alternatively, there's another, easier way which should be right up your street, with the minimum of PHP needed.
Let's assume $level is your variable storing the selected level, taken from $_GET or wherever. Do something like this:
// form stuff
<select name="level">
<?="<option value='$level' selected='selected'>$level</option>"?>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
// etc
</select>
// more form stuff
All you're doing here is adding a dynamic, 'default' selected option which is appended to the top of the list (it can be added anywhere in the list of course, it just makes more sense to me to be at the top). If there's no default option selected (i.e. the $level variable is empty), it just prints out a blank option. If you don't want this, just do:
<? if (!empty($level)) print "<option.. selected..> .. etc "?> so it doesn't print out the option at all!
This is quite a clean way of doing this, without having to print out the whole option set in a loop, so it's more processor-friendly..
Is that alright? :)
Alex ...