|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Selects being Selected Dynamically
Hey all,
Alright, I have a list of countries, and what I want to do, is when the person goes to edit their profile. I want the list to have their country selected (the country is stored in the database). Any ideas? Thanks. |
|
#2
|
|||
|
|||
|
Are your select lists being generated dynamically also?
Do you also need help generating the select county list from the database or do you have that part covered already? The methods for doing this are different depending on whether your list is created dynamically or statically.
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
|
#3
|
|||
|
|||
|
Ya - as laidback has said. To get you partially started, you would (of course) have to have the country id from the users profile to do the conditional on that. The conditional would look something like this:
PHP Code:
__________________
~ Joe Penn We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set? Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you. |
|
#4
|
|||
|
|||
|
The country list is static, but I'm thinking about transferring it to a database with flags and timezone offsets and stuff. Would this be easier to do if it were dynamic?
If it were dynamic, i was thinking of doing something like PHP Code:
There might be some parse errors in there, but I can clean that up. Is that the basic idea though? |
|
#5
|
|||
|
|||
|
Yes - but you still need to put the conditional in there to echo 'selected' when the condition is true.
|
|
#6
|
|||
|
|||
|
Yes, you have the general idea. That is how you would put it together dynamically. Just look at jpenn's if statement and that is how you would have the correct value automatically selected upon page load.
Doing it statically works pretty good too, but the only issue there is that you would always have two entries of the item that is selected. (you would just have a php statement to have that option written to the top of the select element and give it the SELECTED attribute). |
|
#7
|
|||
|
|||
|
Well, this way I have it so it selects the persons country (as via the first query) then adds the rest of the countries under it (Via the second query)
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Selects being Selected Dynamically |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|