0

hello friends i need to make a edit profile page in my website,while registering a user can select multiple locations using multiple select options,so while editing user must get defaultly selected options while registering,i tried using multiple=multiple,but after getting details from databas it must select automaticlly....i cant do that can anyone help me regarding this???
Thanking you in advance!!!

4
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by @developer
0

To make the options selected by default, use the attribute selected="selected" like..

<select>
<option selected="selected"></option>
</select>

You will have to check which all options need to have selected attribute before adding to it.

0

Thank u sir,but my actual problem is i want to select options which are present in database,example consider a situation in editing a profile,if we have a option of selecting multiple options so when we edit our profile we need display previously selecte options,ex:
if he registered during registration as,

<select id="x" multiple="multiple" size="3" >
<option value="blue">blue</option>
<option value="grren">green</option>

<option value="red">red</option>

And if he select red and green when editing it it must display like this

<select id="x" multiple="multiple" size="3" >
<option value="blue">blue</option>
<option value="grren" selected="selected" >green</option>

<option value="red" selected="selected" >red</option>

so how can i get it automatically with values in database,here it is only 3 options so we can do it easily,but i have more than 200 options,so how to do that,please help me

0

OK, so you have the user selected multiple options. So when the user submits the form, you get the selected options as a list which I suppose is saved to the database.

Now while editing the user profile, will have to query and get the selected options from the database. So you get a list of selected values. Now you will have to check against each option whether its in the list, if true, then make it selected.

Since I'm using ColdFusion, I would do something like this..

<select name="sel" multiple="multiple">
	<option value="red" <cfif listFind(myList,"red")> selected="selected"</cfif> >red</option>
</select>

Where 'myList' is the list of selected values from the database and listFind checks whether item "red" is in myList. If it finds, then appends the attribute selected to the option.

Edited by @developer: n/a

0

@developer....good to see more CF developers!

I would assume however that the OP is not using CF, but the premise is the same. To populate a select list with database values, you would need to query the database:


SELECT All data pertaining to this user
WHERE SomeUser = UserInDatabase

This would pull all the relevant data for this user. Then for your select list, you would just populate each one with the database value of that column.

Works pretty much the same way in PHP as well.

Edited by teedoff: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.