Click to See Complete Forum and Search --> : Selected Values


Squid
January 10th, 2005, 02:37 AM
<tr><td> Grades: </td>
<td>
<select name="Grades" >
<option value="1"'.$array[Grades][1].'">GRADE A</option>
<option value="2"'.$array[Grades][2].'">GRADE B</option>
</select>
</td>

The above is a select list. Let's say that we have the value=2 in the database because the user has selected GRADE B, the second option in the list.

Now, user wants to view the data he entered. Still, he would see a select list but this time, in the select list, the GRADE B comes first because it is retrieved from the database as the selected value.

How can I do this? My select list still have GRADE A instead of GRADE B. How can I let my select list comes with GRADE B first?

khp
January 10th, 2005, 08:00 AM
The easy solution would be to print the selected option before the other options.

Assuming that you are doing this in php, you got all the options in an arrary, and the index of the selected item in a scalar variable.

Print the selected option first. unset the selected value in the array. Then loop through array to print the remaining options, using isset to avoid printing anything at the unset index.

Squid
January 10th, 2005, 09:27 PM
I've tried but seems like I still face problems with it. I am still new to PHP. Can someone show me a sample code please?

Thanks in advance.

khp
January 11th, 2005, 02:42 AM
Can someone show me a sample code please?


No, that not quite the way things work around here.
You show us what you have done, and maybe someone will help you fix it.

visualAd
January 11th, 2005, 04:28 AM
Why not use the selected="selected" atrribute to select the correct option. Or am I missing something? :ehh: