Page 1 of 1

setting form selection

Posted: Wed Jan 07, 2004 5:07 pm
by CraniumDesigns
ok, say i have a page where a user can edit their setttings. say one of those things is their, oh i don't know, eye color. say their eye color si already stores as blue, but for some reason they actually meant to set it to green.

ok. if i know how to detect what color it is set as (blue), how do i have a drop down select box that has all the colors avilalable, but since it detects blue as the already set color, that is already selected?

i know in just html it is something like this:

Code: Select all

<select name="eye_color">
			<option value="Blue" selected>Blue</option>
			<option value="Green">Green</option>
                        <option value="Brown">Brown</option>
	    </select>
but how do i set the selected parameter to go to whatever it currently is set at in the DB?

Posted: Wed Jan 07, 2004 5:32 pm
by Gen-ik
There are plenty of ways of doing this. Personaly I use a function() which builds the form (and makes life a whole lot easier) but if you don't know too much about PHP something like the following will also work...

Code: Select all

<select name="eye_color">
<option value="Blue" <?php if($eyeColor=="Blue") echo "select="selected"" ?>>Blue</option>
<option value="Green" <?php if($eyeColor=="Green") echo "select="selected"" ?>>Green</option>
</select>

Posted: Wed Jan 07, 2004 5:37 pm
by scorphus
Also, take a look to this Code Snippet I wrote: PHP/HTML: Print <select><options></select> and also the examples in the reply. It may help you on this matter.

Regards,
Scorphus.