highlight item in dropdown box

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
spursystarman
New php-forum User
New php-forum User
Posts: 2
Joined: Sun May 19, 2019 6:50 am

Sun May 19, 2019 7:00 am

Hi,
I have a (pre-typed, static) dropdown box containing a list of British counties. The list is pure HTML, and doesn't change. When a user registers, they pick an item from this list which then gets sent to the DB.
For example let's say user xyz picked "Norfolk" as the region when he registered, so that was stored in his DB record. When user xyz logs in, I need to see "Norfolk" highlighted in the dropdown box.
That's all!

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 845
Joined: Mon Feb 22, 2016 5:52 pm

Sun May 19, 2019 7:24 am

pre-typed, static
is a problem: although you can set an item as selected, that requires parsing the html to find the correct item and then inserting the selected attribute.

You would be better off storing the counties in a database table or an included array, then parse the list until you get the chosen county to set as you populate the html list.

Alternatively: I don't see the point in showing a list of counties unless the user wants to change it, they have already chosen the county, so just show them that.

spursystarman
New php-forum User
New php-forum User
Posts: 2
Joined: Sun May 19, 2019 6:50 am

Sun May 19, 2019 12:22 pm

Thanks for that. In fact I have decided on a different option (pardon the pun!) but that doesn't mean I am not thankful for the suggestion. Cheers.

Post Reply